Questions tagged [uibarbuttonitem]

UIBarButtonItem is a button specialized for placement on a UIToolbar or UINavigationBar object. It inherits basic button behavior from its abstract superclass, UIBarItem. The UIBarButtonItem defines additional initialisation methods and properties for use on toolbars and navigation bars. There are some methods for customizing Appearance. Available in iOS 2.0 and later in UIKit.

A bar button item is a button specialized for placement on a UIToolbar or UINavigationBar objects. It inherits basic button behavior from its abstract superclass, UIBarItem. The UIBarButtonItem defines additional initialization methods and properties for use on toolbars and navigation bars.

iOS includes a number of system-provided items with specific icons, but developers can create custom items as well.

Note: UIBarButtonItem is not a descendent of UIView, so many common tasks like applying animations or transforms can be more difficult than you might expect.

UIBarButtonItem Class Reference

2349 questions
31
votes
2 answers

Placing a custom view based UIBarButtonItem in the navigation bar without default horizontal padding

How do I remove the horizontal padding to the left and right of custom left and right UINavigationBar items? There seems to be ~ 10 points of padding that iOS sets by default. I'm customizing left and right navigation bar buttons (I have given up on…
idStar
  • 10,674
  • 9
  • 54
  • 57
30
votes
7 answers

titleTextAttributes UIAppearance font in iOS 7

I am using UIAppearance to apply fonts to UINavigationBar and UIBarButtonItem and I am having problems. I ran this code: [[UIBarButtonItem appearanceWhenContainedIn:[UIToolbar class], nil] setTitleTextAttributes: @{NSFontAttributeName : [UIFont…
LOP_Luke
  • 3,150
  • 3
  • 22
  • 25
29
votes
13 answers

Swift add badge to navigation barButtonItem and UIButton

I am trying to display badge on my notification button, in app as displayed on AppIcon. So far whatever i have researched is related to Obj. C, but nothing that specifically discussed way to implement that solution into Swift, Please help to find…
coolagrwal
  • 293
  • 1
  • 4
  • 7
27
votes
6 answers

How do I set title for UIBarButtonItem?

I'm a beginner iPhone developer. How can I programmatically set the title for the UIBarButtonItem? My code is the following: self.navigationItem.rightBarButtonItems = UIBarButtonItem( barButtonSystemItem: .Cancel, target: self, …
KSL
  • 307
  • 1
  • 3
  • 6
27
votes
5 answers

Change font of back button on UINavigationController

I'm trying to change the font color of the text on my back button in my UINavigationControllerBar: [[UIBarButtonItem appearance] setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; I get this error: [_UIBarItemAppearance…
26
votes
6 answers

setting image for UIBarButtonItem - image stretched

When I try to use UIBarButtonItem's "initWithImage" to initialize a navigation bar custom image, it comes out washed-up and stretched against a black navigation bar. This is how I create it: UIBarButtonItem *button = [[UIBarButtonItem alloc]…
Z S
  • 7,039
  • 12
  • 53
  • 105
25
votes
1 answer

iOS 5: Positioning Bar Button Item in a toolbar with Xcode/Storyboard

I have an existing toolbar in my View... when I drag a "Bar Button Item" into the tool bar it gets slammed to left side of the toolbar (I would like it to sit on the right edge). Attempting to drag the Bar Button only results in it being "gravity…
Electro-Bunny
  • 1,380
  • 2
  • 12
  • 33
25
votes
4 answers

How to align UIBarButtonItem in UIToolbar in iOS universal app?

I want to put two UIBarButtonItem instances to UIToolbar in my iOS universal app, on which the first item is on the left-edge of the toolbar and the second is on the center. However, it looks like this cannot be done in Interface Builder, because…
Blaszard
  • 30,954
  • 51
  • 153
  • 233
25
votes
6 answers

Change width of a UIBarButtonItem in a UINavigationBar

I am creating a UIBarButtonItem and adding it to my navigation bar like so: (void)viewDidLoad { ... // Add the refresh button to the navigation bar UIButton *refreshButton = [UIButton buttonWithType:UIButtonTypeCustom]; [refreshButton…
Darren
  • 10,091
  • 18
  • 65
  • 108
24
votes
8 answers

UIBarButtonItem changing title not working

How can I change the title of a UIBarButtonItem? I have the following code which is called when an edit button is pressed on my UINavigationBar. -(void)editButtonSelected:(id)sender { NSLog(@"edit button selected!"); if(editing) { …
CodeGuy
  • 28,427
  • 76
  • 200
  • 317
24
votes
6 answers

Multiple UIBarButtonItems in UINavigationBar

How to Create multiple bar button in navigation bar?
Kshitiz Ghimire
  • 1,716
  • 3
  • 18
  • 37
24
votes
7 answers

How to programmatically create a "Back" UIBarButton item in Swift?

I was able to create a UIBarButton item that can go back programmatically using the following code: func backAction() -> Void { self.navigationController?.popViewControllerAnimated(true) } override func viewDidLoad() { …
Rami Ammoun
  • 855
  • 2
  • 10
  • 25
24
votes
3 answers

How do you adjust the frame or vertical alignment of a UIBarButtonItem contained by a UIToolbar instance?

Horizontal positioning of UIBarButtonItems is no problem, I can simply pad the space with fixed/flexible space items. However, I can't seem to adjust the toolbar item vertically. UIToolbar has no alignment property, and UIBarButtonItem has no way of…
akaii
  • 457
  • 1
  • 6
  • 15
24
votes
3 answers

iOS Autolayout and UIToolbar/UIBarButtonItems

I have an iOS view with autolayout enabled and have a UIToolbar with a UISearchBar and UISegmentControl contained with the toolbar. I want the UISearchBar to have a flexible width so I need to add a constraint to force this, but from what I can…
outerstorm
  • 712
  • 3
  • 7
  • 16
24
votes
3 answers

Navigation bar with multiple buttons

I have a navigation bar with a left and right button, and I need to put another button next to the right button. Does anyone know how I can go about this? Here is some code to help: - (id)init { self = [super…