iOS Developer Library — Prerelease

Developer

UIKit Framework Reference UIBarItem Class Reference

Options
Deployment Target:

On This Page
Language:

UIBarItem

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]).

  • 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.

    Availability

    Available in iOS 2.0 and later.

  • The image used to represent the item.

    Declaration

    Swift

    var image: UIImage?

    Objective-C

    @property(nonatomic, strong) 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.

    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, strong) 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.

    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.

    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.

    Availability

    Available in iOS 5.0 and later.

  • 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.

    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.

    Availability

    Available in iOS 2.0 and later.