Change position of UIBarButtonItem in UINavigationBar

后端 未结 20 1517
一个人的身影
一个人的身影 2020-11-27 10:31

How can I change the position of a UIBarButtonItem in a UINavigationBar? I would like my button to be about 5px higher than its normal position.

20条回答
  •  死守一世寂寞
    2020-11-27 11:16

    Init UIBarButtonItem with custom view and overload layoutSubviews in custom view, like this

    -(void) layoutSubviews {
      [super layoutSubviews];
      CGRect frame = self.frame;
      CGFloat offsetY = 5;
      frame.origin.y = (44 - frame.size.height) / 2 - offsetY;
      self.frame = frame;
    }
    

提交回复
热议问题