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

前端 未结 2 1930
礼貌的吻别
礼貌的吻别 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;
    }
    

提交回复
热议问题