1

I want to create a bottom tab that could change the view when user press.

To do that I create a view with view controller and sets it's frame in the init

Here is the bottom panel view controller

@implementation BottomTabViewController

-(id) initWithFrame:(CGRect)frame{
    if(self = [super init]){
        self.view.frame = frame;
        return self;
    }else{
        return nil;
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpButtons];
    // Do any additional setup after loading the view.
}

-(void) featureBtnClick:(id*) sender{
    NSLog(@"featureBtn Clicked");
}

-(void) favBtnClick:(id*)sender{
    NSLog(@"Fav Btn Clicked");
}

-(void) setUpButtons{
    UIButton *features = [[UIButton alloc]initWithFrame:CGRectMake(10, 10, 50, 50)];
    [features setBackgroundImage:[UIImage imageNamed:@"feature.png"] forState:UIControlStateNormal];
    features.backgroundColor = [UIColor greenColor];

    [features addTarget:self action:@selector(featureBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:features];

    UIButton *favBtn = [[UIButton alloc]initWithFrame:CGRectMake([[UIScreen mainScreen]bounds].size.width - 100, 10, 50, 50)];
    [favBtn setBackgroundImage:[UIImage imageNamed:@"favorite.png"] forState:UIControlStateNormal];
    [favBtn addTarget:self action:@selector(favBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    favBtn.backgroundColor = [UIColor greenColor];

    [self.view addSubview:favBtn];

}


@end

And I added that to my view with code like this:

-(void) setUpBottom{

    BottomTabViewController *botm = [[BottomTabViewController alloc]initWithFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height - 55, [[UIScreen mainScreen]bounds].size.width, 55)];
    botm.view.backgroundColor = [UIColor redColor];
   // botm.view.userInteractionEnabled = false;
    botm.view.userInteractionEnabled = true;
    [self.view addSubview:botm.view];
}

Here here is the result seems, note the bottom panel that works, well pretty silly, but it shows up:

enter image description here But when press the left and right button, there is not log printed which it expected to be to indict that the button works, What have I done wrong? Thanks

armnotstrong
  • 8,605
  • 16
  • 65
  • 130

1 Answers1

0

you are adding buttons in the view first then adding the bottom view. if this is what you are doing then it can be overlapped by the bottom view. In this case buttons cant be tapped because they have bottom view on top of them. so make sure u add bottom view first then your buttons. (or change their frames to avoid overlapping)

Wasi Tariq
  • 21
  • 2