Change position of UIBarButtonItem in UINavigationBar

后端 未结 20 1507
一个人的身影
一个人的身影 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:11

    Here is a simple workaround that was sufficient for my needs. I added an info button on the right hand side of the UINavigationBar but by default it sits way too close to the edge. By extending the width of the frame I was able to create the extra spacing needed on the right.

     UIButton *info = [UIButton buttonWithType:UIButtonTypeInfoLight];
     CGRect frame = info.frame;
     frame.size.width += 20;
     info.frame = frame;
     myNavigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]initWithCustomView:info]autorelease];
    

提交回复
热议问题