Custom UINavigationBar with custom height causes the UIBarButtonItem's to be positioned wrong

前端 未结 2 1926
礼貌的吻别
礼貌的吻别 2021-01-31 11:49

I created my own subclass of UINavigationBar in order to enable custom background that is taller than 44pxs.

I did it by overriding these two methods:

-(         


        
相关标签:
2条回答
  • 2021-01-31 12:14

    To solve the push/pop issue use setTitleVerticalPositionAdjustment in sizeThatFits:(CGSize)size

    - (CGSize)sizeThatFits:(CGSize)size {
        UIImage *img = [UIImage imageNamed:@"navigation_background.png"];
        [self setTitleVerticalPositionAdjustment:-7 forBarMetrics:UIBarMetricsDefault];
        CGRect frame = [UIScreen mainScreen].applicationFrame;
        CGSize newSize = CGSizeMake(frame.size.width , img.size.height);
        return newSize;
    }
    
    0 讨论(0)
  • 2021-01-31 12:28

    Try to override layoutSubviews: call [super layoutSubviews] inside and then reposition the items.

    0 讨论(0)
提交回复
热议问题