UIBarButtonItem

UIBarItem

UIBarButtonItem

UINavigationController

UINavigationBar

UIToolbar


  1. Initializing an Item
  2. Getting and Setting Properties
  3. Customizing Appearance
  4. Getting the Shortcuts Group Information

UIBarButtonItem就是我们在UIToolbar和UINavigationBar上看见的按钮。

如果你要改变UIBarButtonItem的全局样式,可以通过UIBarButtonItem.appearance()获取全局UIBarButtonItem。

1 Initializing an Item

/// 通过图片初始化UIBarButtonItem
public convenience init(image: UIImage?, style: UIBarButtonItemStyle, target: AnyObject?, action: Selector)

/// 通过图片初始化UIBarButtonItem,横竖屏可不一致
@available(iOS 5.0, *)
public convenience init(image: UIImage?, landscapeImagePhone: UIImage?, style: UIBarButtonItemStyle, target: AnyObject?, action: Selector)

/// 通过文字初始化UIBarButtonItem
public convenience init(title: String?, style: UIBarButtonItemStyle, target: AnyObject?, action: Selector)

/// 通过系统样式初始化UIBarButtonItem
public convenience init(barButtonSystemItem systemItem: UIBarButtonSystemItem, target: AnyObject?, action: Selector)

/// 通过自定义View初始化UIBarButtonItem
public convenience init(customView: UIView)

2 Getting and Setting Properties

/// 系统点击样式
public var style: UIBarButtonItemStyle
/// 按钮宽
public var width: CGFloat
/// 可能显示的标题
public var possibleTitles: Set<String>?
/// 按钮自定义的UIView
public var customView: UIView?
/// 点击按钮的接收器
public var action: Selector
/// 点击按钮执行的方法
weak public var target: AnyObject?

3 Customizing Appearance

/// 设置背景图片
@available(iOS 5.0, *)
public func setBackgroundImage(backgroundImage: UIImage?, forState state: UIControlState, barMetrics: UIBarMetrics)
/// 获取背景图片
@available(iOS 5.0, *)
public func backgroundImageForState(state: UIControlState, barMetrics: UIBarMetrics) -> UIImage?

/// 设置背景图片
@available(iOS 6.0, *)
public func setBackgroundImage(backgroundImage: UIImage?, forState state: UIControlState, style: UIBarButtonItemStyle, barMetrics: UIBarMetrics)
@available(iOS 6.0, *)
/// 获取背景图片
public func backgroundImageForState(state: UIControlState, style: UIBarButtonItemStyle, barMetrics: UIBarMetrics) -> UIImage?

/// 按钮颜色
@available(iOS 5.0, *)
public var tintColor: UIColor?

/// 调整垂直方向的位置
@available(iOS 5.0, *)
public func setBackgroundVerticalPositionAdjustment(adjustment: CGFloat, forBarMetrics barMetrics: UIBarMetrics)
/// 获取垂直方向的位置
@available(iOS 5.0, *)
public func backgroundVerticalPositionAdjustmentForBarMetrics(barMetrics: UIBarMetrics) -> CGFloat

/// 设置标题位置
@available(iOS 5.0, *)
public func setTitlePositionAdjustment(adjustment: UIOffset, forBarMetrics barMetrics: UIBarMetrics)
/// 获取标题位置
@available(iOS 5.0, *)
public func titlePositionAdjustmentForBarMetrics(barMetrics: UIBarMetrics) -> UIOffset


// MARK: - 后退按钮

/// 后退按钮的图片
@available(iOS 5.0, *)
public func setBackButtonBackgroundImage(backgroundImage: UIImage?, forState state: UIControlState, barMetrics: UIBarMetrics)
/// 获取后退按钮的图片
@available(iOS 5.0, *)
public func backButtonBackgroundImageForState(state: UIControlState, barMetrics: UIBarMetrics) -> UIImage?

/// 设置后退按钮的字体样式
@available(iOS 5.0, *)
public func setBackButtonTitlePositionAdjustment(adjustment: UIOffset, forBarMetrics barMetrics: UIBarMetrics)
/// 获取后退按钮的字体样式
@available(iOS 5.0, *)
public func backButtonTitlePositionAdjustmentForBarMetrics(barMetrics: UIBarMetrics) -> UIOffset

/// 设置后退按钮标题位置
@available(iOS 5.0, *)
public func setBackButtonBackgroundVerticalPositionAdjustment(adjustment: CGFloat, forBarMetrics barMetrics: UIBarMetrics)
/// 获取后退按钮标题位置
@available(iOS 5.0, *)
public func backButtonBackgroundVerticalPositionAdjustmentForBarMetrics(barMetrics: UIBarMetrics) -> CGFloat

4 Getting the Shortcuts Group Information

/// 按钮管理的按钮组
@available(iOS 9.0, *)
weak public var buttonGroup: UIBarButtonItemGroup? { get }

 


Appendix

Sample Code

Swift

UIKit Framework Reference

UIBarButtonItem Class Reference

Revision History

时间描述
2016-01-11博文完成

CSDN:http://blog.csdn.net/y550918116j

GitHub:https://github.com/937447974/Blog

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值