UIButton

基本属性

@property(nonatomic) UIEdgeInsets contentEdgeInsets; 内容内距离
@property(nonatomic) UIEdgeInsets titleEdgeInsets; 标题内距离
@property(nonatomic) BOOL reversesTitleShadowWhenHighlighted; 标题的阴影改变时,按钮是否高亮显示。默认为NO
@property(nonatomic) UIEdgeInsets imageEdgeInsets; 图片内边距
@property(nonatomic) BOOL adjustsImageWhenHighlighted;按钮高亮的情况下,图像的颜色是否要加深一点。默认是YES
@property(nonatomic) BOOL adjustsImageWhenDisabled; 按钮禁用的情况下,图像的颜色是否要加深一点。默认是YES
@property(nonatomic) BOOL showsTouchWhenHighlighted; 按下按钮是否会发光 默认是NO
@property(nonatomic,readonly) UIButtonType buttonType; button的类型
@property(nullable, nonatomic,readonly,strong) NSString *currentTitle; 获取按钮当前标题
@property(nonatomic,readonly,strong) UIColor *currentTitleColor; 获取按钮当前标题颜色
@property(nullable, nonatomic,readonly,strong) UIColor *currentTitleShadowColor; 获取按钮当前阴影标题颜色
@property(nullable, nonatomic,readonly,strong) UIImage *currentImage; 获取按钮当前按钮内图像
@property(nullable, nonatomic,readonly,strong) UIImage *currentBackgroundImage; 获取按钮当前标题背景图片
@property(nullable, nonatomic,readonly,strong) NSAttributedString *currentAttributedTitle 获取按钮当前标题富文本
@property(nullable, nonatomic,readonly,strong) UILabel *titleLabel NS_AVAILABLE_IOS(3_0);


 基本方法

 


其他

  • 为了保证高亮状态下的图片正常显示,必须设置按钮的type为custom;

 相关的枚举

typedef NS_ENUM(NSInteger, UIButtonType) {
    UIButtonTypeCustom = 0,                         -自定义风格
    UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0),  // standard system button
    UIButtonTypeDetailDisclosure,                   -蓝色小箭头按钮,主要做详细说明
    UIButtonTypeInfoLight,                             -亮色感叹号
    UIButtonTypeInfoDark,                             -暗色感叹号
    UIButtonTypeContactAdd,                        -十字加号按钮
};

事件枚举值:
UIControlEventTouchDown // 单点触摸按下事件:用户点触屏幕,或者又有新手指落下的时候。
UIControlEventTouchDownRepeat // 多点触摸按下事件,点触计数大于1:用户按下第二、三、或第四根手指的时候。
UIControlEventTouchDragInside // 当一次触摸在控件窗口内拖动时。
UIControlEventTouchDragOutside // 当一次触摸在控件窗口之外拖动时。
UIControlEventTouchDragEnter // 当一次触摸从控件窗口之外拖动到内部时
UIControlEventTouchDragExit // 当一次触摸从控件窗口内部拖动到外部时。
UIControlEventTouchUpInside // 所有在控件之内触摸抬起事件
UIControlEventTouchUpOutside // 所有在控件之外触摸抬起事件(点触必须开始与控件内部才会发送通知)。
UIControlEventTouchCancel // 所有触摸取消事件,即一次触摸因为放上了太多手指而被取消,或者被上锁或者电话呼叫打断。
UIControlEventValueChanged // 当控件的值发生改变时,发送通知。用于滑块、分段控件、以及其他取值的控件。你可以配置滑块控件何时发送通知,在滑块被放下时发送,或者在被拖动时发送。
UIControlEventEditingDidBegin // 当文本控件中开始编辑时发送通知
UIControlEventEditingChanged // 当文本控件中的文本被改变时发送通知。
UIControlEventEditingDidEnd // 当文本控件中编辑结束时发送通知。
UIControlEventEditingDidEndOnExit // 当文本控件内通过按下回车键(或等价行为)结束编辑时,发送通知。
UIControlEventAllTouchEvents // 通知所有触摸事件。
UIControlEventAllEditingEvents // 通知所有关于文本编辑的事件。
UIControlEventApplicationReserved // range available for application use
UIControlEventSystemReserved // range reserved for internal framework use
UIControlEventAllEvents // 通知所有事件

原文地址:https://www.cnblogs.com/jingdizhiwa/p/5902582.html