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.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- back button text does not change
相关文章
- 现在使用swift开发ios应用好还是swift?
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
The best way is to subclass your UINavigationBar, as described here: https://stackoverflow.com/a/17434530/1351190
Here is my example:
Hope it helps.
There is no particularly good way to do this. Your best bet if you really must is to subclass UINavigationBar, and override
layoutSubviews
to call[super layoutSubviews]
and then find and reposition the button's view.Step 1: Set title position using Appearance API. For example, in AppDelegate's didFinishLaunchingWithOptions
Step 2: Subclass UINavigationBar
Navigation bar using change left bar position and image edge insets
swift 4
This code creates a back button for UINavigationBar with image background and custom position. The trick is to create an intermediate view and modify its bounds.
Try the code below,
Its used to change the 'y' position in this code. Change the 'y' value (here it is -20.0f) according to your requirement. If the value is positive, it will down the button position. If the value is negative, it will up your button position.