remy boys
remy boys

Reputation: 2948

passing Events from UIButton to TabBarItem

i wanted to make my UITabBarItem's size Bigger then other buttons so i tried this in Subclass of TabBarController :

var button = UIButton(type: .Custom)
button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height)
button.setBackgroundImage(buttonImage, forState: .Normal)
button.setBackgroundImage(highlightImage, forState: .Highlighted)
var heightDifference: CGFloat = buttonImage.size.height - self.tabBar.frame.size.height
if heightDifference < 0 {
    button.center = self.tabBar.center
}
else {
    var center = self.tabBar.center
    center.y = center.y - heightDifference / 2.0
    button.center = center
}
self.view.addSubview(button)

it worked fine cause now i have a Button on top of my BarButtonItem (expected Behavior ) but now this new button is blocking the TouchEvents which supposed to handle by barbuttonitem , any idea how can i solve this problem ?? i followed this article for getting this newButton:

what i want is look like this : enter image description here

SOLVED:

All i needed was to disable the user interaction for my button.

Upvotes: 0

Views: 32

Answers (1)

mrunal thanki
mrunal thanki

Reputation: 751

you can try below code for your UIButton Clicked event e.g.

-(void)clickedEvent:(id)sender{
    .... some code
    [self.tabBarController setSelectedIndex:2];
    ..... some code
}

Hopefully, It should work.

Upvotes: 1

Related Questions