Change the height of NavigationBar and UIBarButtonItem elements inside it in Cocoa Touch

后端 未结 6 2079
忘了有多久
忘了有多久 2020-12-23 15:19

I suppose it\'s not strictly in line with Apple guidelines but I guess it must be possible somehow. I\'d like to change the height of navigation bar inside UINavigationContr

6条回答
  •  不知归路
    2020-12-23 15:48

    I managed to do something similar by subclassing UINavigationBar and overriding -layoutSubviews. The code looks like:

    -(void)layoutSubviews {
        [super layoutSubviews];
        int i = 0;
        for (UIView *view in self.subviews) {
            NSLog(@"%i. %@", i++, [view description]);
            if ([view isKindOfClass:NSClassFromString(@"UINavigationButton")]) {
                view.frame = CGRectMake(0, 0, 100, 50);
            }
        }
    }
    

    If you need to know how to subclass UINavigationBar, have a look at this very good answer.

    I am not really sure about the NSClassFromString(@"UINavigationButton")] part. It works, but I did this as an experiment, and I'm not sure if this will get approved by Apple. I hope someone with a better knowledge might shed some light.

提交回复
热议问题