Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Position UIBarButtonItem on edge of UINavigationBar

Is it possible to position a custom image UIBarButton item on the left or right edge of a UINavigationBar? The way I've created my buttons it looks best if the edge of the button is touching the edge of the UINavigationBar.

like image 754
mhbdr Avatar asked Nov 13 '22 04:11

mhbdr


1 Answers

Your best bet here is subclassing UINavigation bar and overriding layout subviews.

In my example I move my button to the far left edge if it has a tag of 900.

- (void) layoutSubviews {
    [super layoutSubviews];
    //override the navigation bar to move classes with 900 to the ledge
    for (UIView *view in self.subviews) {  
        if ([view isKindOfClass:[UIButton class]]) {  
            if (view.tag == 900)
                view.frame = CGRectMake(0,0, 88, 44);
        }

    }
}
like image 158
mattvv Avatar answered Dec 07 '22 00:12

mattvv