I want to create UIBarButtonItems
programmatically and place these fixed space items between buttons.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- how do you prevent page scroll in textarea on mobi
- Custom UITableview cell accessibility not working
相关文章
- Could I create “Call” button in HTML 5 IPhone appl
- xcode 4 garbage collection removed?
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
- Popover segue to static cell UITableView causes co
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
- didBeginContact:(SKPhysicsContact *)contact not in
With Swift 3,
UIBarButtonItem
has an initializer calledinit(barButtonSystemItem:target:action:)
.init(barButtonSystemItem:target:action:)
has the following declaration:UIBarButtonSystemItem
is an enumeration that offers many cases includingdone
,play
,add
orcancel
. However, according to your needs, you may also chooseflexibleSpace
orfixedSpace
cases.flexibleSpace
case has the following declaration:fixedSpace
case has the following declaration:Therefore, you can create fixed and flexible space bar button items programmatically as shown below:
As an example, the Playground code below shows how to add a bottom bar with two centered play and pause bar button items separated by a fixed space of 30 in a view controller:
Preview your view controller in the Playground assistant editor using View ▸ Assistant Editor ▸ Show Assistant Editor
Swift
In ViewDidLoad:
Do not forget the actions for each button also(in this example a UIWebView):
etc.