UIBarButtonItem.h
1、UIBarButtonItemStyle:
UIBarButtonItemStylePlain:纯文本风格,默认按钮的风格,按下时会闪动;
UIBarButtonItemStyleBordered:与UIBarButtonItemStylePlain显示相同,但显示的按钮有边框;
UIBarButtonItemStyleDone:一个加粗蓝色的按钮;
2、UIBarButtonSystemItem:
UIBarButtonSystemItemDone, //Done按钮
UIBarButtonSystemItemCancel, //Cancel按钮
UIBarButtonSystemItemEdit, //Edit按钮
UIBarButtonSystemItemSave, //Save按钮
UIBarButtonSystemItemAdd, //+号按钮
UIBarButtonSystemItemFlexibleSpace, //可变宽度的占位按钮
UIBarButtonSystemItemFixedSpace, //固定宽度
UIBarButtonSystemItemCompose,
UIBarButtonSystemItemReply, //回复按钮
UIBarButtonSystemItemAction, //
UIBarButtonSystemItemOrganize, //
UIBarButtonSystemItemBookmarks, //
UIBarButtonSystemItemSearch, //
UIBarButtonSystemItemRefresh, //
UIBarButtonSystemItemStop, //
UIBarButtonSystemItemCamera, //
UIBarButtonSystemItemTrash, //
UIBarButtonSystemItemPlay, //
UIBarButtonSystemItemPause, //
UIBarButtonSystemItemRewind, //
UIBarButtonSystemItemFastForward, //
UIBarButtonSystemItemUndo NS_ENUM_AVAILABLE_IOS(3_0), //
UIBarButtonSystemItemRedo NS_ENUM_AVAILABLE_IOS(3_0), //
UIBarButtonSystemItemPageCurl NS_ENUM_AVAILABLE_IOS(4_0), //
3、初始化UIBArButtonItem的方法
- (instancetype)init NS_DESIGNATED_INITIALIZER;
//初始化实例变量,用反序列化数据构造
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;
//使用图片初始化
- (instancetype)initWithImage:(nullable UIImage *)image style:(UIBarButtonItemStyle)style target:(nullable id)target action:(nullable SEL)action;
- (instancetype)initWithImage:(nullable UIImage *)image landscapeImagePhone:(nullable UIImage *)landscapeImagePhone style:(UIBarButtonItemStyle)style target:(nullable id)target action:(nullable SEL)action NS_AVAILABLE_IOS(5_0); // landscapeImagePhone will be used for the bar button image when the bar has Compact or Condensed bar metrics.
//初始化时设置按钮标题
- (instancetype)initWithTitle:(nullable NSString *)title style:(UIBarButtonItemStyle)style target:(nullable id)target action:(nullable SEL)action;
//使用(2、UIBarButtonSystemItem)中的风格初始化按钮为系统风格
- (instancetype)initWithBarButtonSystemItem:(UIBarButtonSystemItem)systemItem target:(nullable id)target action:(nullable SEL)action;
//使用自定义按钮初始化
- (instancetype)initWithCustomView:(UIView *)customView;
4、按钮的面貌修改方法
//为任意风格的按钮设置背景图片
- (void)setBackgroundImage:(nullable UIImage *)backgroundImage forState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
- (nullable UIImage *)backgroundImageForState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
//为特定风格的按钮设置背景图片,当时UIBarButtonItem实例调用下面方法时,其风格必须和按钮风格一致
- (void)setBackgroundImage:(nullable UIImage *)backgroundImage forState:(UIControlState)state style:(UIBarButtonItemStyle)style barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
- (nullable UIImage *)backgroundImageForState:(UIControlState)state style:(UIBarButtonItemStyle)style barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
//为有边框的按钮调节其在bar中的垂直中心的位置
- (void)setBackgroundVerticalPositionAdjustment:(CGFloat)adjustment forBarMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
- (CGFloat)backgroundVerticalPositionAdjustmentForBarMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
//调节有边框按钮的文字在bar中的位置
- (void)setTitlePositionAdjustment:(UIOffset)adjustment forBarMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
- (UIOffset)titlePositionAdjustmentForBarMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
//以上所有的修改方法针对导航栏的返回按钮有专门对应的方法
- (void)setBackButtonBackgroundImage:(nullable UIImage *)backgroundImage forState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR __TVOS_PROHIBITED;
- (nullable UIImage *)backButtonBackgroundImageForState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR __TVOS_PROHIBITED;
- (void)setBackButtonTitlePositionAdjustment:(UIOffset)adjustment forBarMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR __TVOS_PROHIBITED;
- (UIOffset)backButtonTitlePositionAdjustmentForBarMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR __TVOS_PROHIBITED;
- (void)setBackButtonBackgroundVerticalPositionAdjustment:(CGFloat)adjustment forBarMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR __TVOS_PROHIBITED;
- (CGFloat)backButtonBackgroundVerticalPositionAdjustmentForBarMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR __TVOS_PROHIBITED;