iOS Developer Library — Pre-Release

Developer

UIKit Framework Reference UIBarItem Class Reference

Options
Deployment Target:

On This Page
Language:

UIBarItem

Conforms To


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 2.0 and later.

UIBarItem is an abstract superclass for items added to a bar that appears at the bottom of the screen. Items on a bar behave in a way similar to buttons (instances of UIButton). They have a title, image, action, and target. You can also enable and disable an item on a bar.

Customizing Appearance

You can customize the image to represent the item, and the position of the image, using imageand imageInsets respectively.

In iOS v5.0 and later, you can also specify a custom image and position to use in landscape orientation when using the iPhone appearance idiom using landscapeImagePhoneand landscapeImagePhoneInsets respectively. In addition, you can customize the title’s text attributes using setTitleTextAttributes:forState:, either for a single item, or for all items by using the appearance proxy (for example, [UIBarItem appearance]).

  • enabled enabled Property

    A Boolean value indicating whether the item is enabled.

    Declaration

    Swift

    var enabled: Bool

    Objective-C

    @property(nonatomic, getter=isEnabled) BOOL enabled

    Discussion

    If NOfalse, the item is drawn partially dimmed to indicate it is disabled. The default value is YEStrue.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • image image Property

    The image used to represent the item.

    Declaration

    Swift

    var image: UIImage?

    Objective-C

    @property(nonatomic, retain) UIImage *image

    Discussion

    This image can be used to create other images to represent this item on the bar—for example, a selected and unselected image may be derived from this image. You should set this property before adding the item to a bar. The default value is nil.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The image to use to represent the item in landscape orientation when using the iPhone appearance idiom.

    Declaration

    Swift

    var landscapeImagePhone: UIImage?

    Objective-C

    @property(nonatomic, retain) UIImage *landscapeImagePhone

    Discussion

    This image can be used to create other images to represent this item on the bar—for example, a selected and unselected image may be derived from this image. You should set this property before adding the item to a bar. The default value is nil.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • The image inset or outset for each edge.

    Declaration

    Swift

    var imageInsets: UIEdgeInsets

    Objective-C

    @property(nonatomic) UIEdgeInsets imageInsets

    Discussion

    The default value is UIEdgeInsetsZero.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The image inset or outset for each edge of the image in landscape orientation when using the iPhone appearance idiom.

    Declaration

    Swift

    var landscapeImagePhoneInsets: UIEdgeInsets

    Objective-C

    @property(nonatomic) UIEdgeInsets landscapeImagePhoneInsets

    Discussion

    The default value is UIEdgeInsetsZero.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • title title Property

    The title displayed on the item.

    Declaration

    Swift

    var title: String?

    Objective-C

    @property(nonatomic, copy) NSString *title

    Discussion

    You should set this property before adding the item to a bar. The default value is nil.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • tag tag Property

    The receiver’s tag, an application-supplied integer that you can use to identify bar item objects in your application.

    Declaration

    Swift

    var tag: Int

    Objective-C

    @property(nonatomic) NSInteger tag

    Discussion

    The default value is 0.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Sets the title’s text attributes for a given control state.

    Declaration

    Swift

    func setTitleTextAttributes(_ attributes: [NSObject : AnyObject]!, forState state: UIControlState)

    Objective-C

    - (void)setTitleTextAttributes:(NSDictionary *)attributes forState:(UIControlState)state

    Parameters

    attributes

    A dictionary containing key-value pairs for text attributes.

    You can specify the font, text color, text shadow color, and text shadow offset using the keys listed in NSString UIKit Additions Reference.

    state

    The control state for which you want to set the text attributes for the title.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • Returns the title’s text attributes for a given control state.

    Declaration

    Swift

    func titleTextAttributesForState(_ state: UIControlState) -> [NSObject : AnyObject]!

    Objective-C

    - (NSDictionary *)titleTextAttributesForState:(UIControlState)state

    Parameters

    state

    The control state for which you want to know the text attributes for the title.

    Return Value

    The title’s text attributes for state.

    Discussion

    The dictionary may contain key-value pairs for text attributes for the font, text color, text shadow color, and text shadow offset using the keys listed in NSString UIKit Additions Reference.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.