Horizontally repositioning a UIBarButtonItem

2019-07-15 12:56发布

Is it possible to reposition a UIBarButtonItem that's in a UINavigationBar horizontally? I've seen the barButtonItem setBackgroundVerticalPositionAdjustment:forBarMetrics: method (but that's for vertical positioning), and I know how to do it if I make it a custom button, but how do I take a UIBarButtonItem with the style UIBarButtonItemStyleBordered and horizontally reposition it (that is, move it left or right)?

Thanks in advance!

1条回答
【Aperson】
2楼-- · 2019-07-15 13:25

You can create a fixed size button as a 'filler' and add that to beside your existing button:

UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];

(Then set the width to your desired value)

查看更多
登录 后发表回答