1.创建 + buttonWithType: // 创建并返回一个特定风格的按钮 2.设置标题 buttonType property titleLabel property // 显示按钮当前标题的视图(只读).虽然它是只读的,但是它的属性是可读写的.它的属性在按钮还没有显示之前就有返回值.系统按钮这些值为nil reversesTitleShadowWhenHighlighted property // 确定按钮高亮时是否改变阴影的Bool值.默认时NO,当为YES时,阴影在雕刻与浮雕感之间变化(差不多就是去正常offset的相反数作为新的offset) – setTitle:forState: // 设置不同状态的标题,不同状态默认的标题是UIControlStateNormal时的值.若normal状态的值没有设定,默认是个系统值,所以你只要要设置normal状态 – setTitleColor:forState: // 设置不同状态时的标题颜色.不同状态默认的标题颜色是UIControlStateNormal时的值.若normal状态的值没有设定,默认是个系统值,所以你只要要设置normal状态 – setTitleShadowColor:forState: // 设置不同状态时的标题阴影颜色.不同状态默认的标题阴影颜色是UIControlStateNormal时的值.若normal状态的值没有设定,默认是个系统值,所以你只要要设置normal状态 – titleColorForState: // 返回不同状态时标题颜色. – titleForState: // 返回不同状态时的标题 – titleShadowColorForState: // 返回不同状态时的标题阴影颜色 font property Deprecated in iOS 3.0 lineBreakMode property Deprecated in iOS 3.0 titleShadowOffset property Deprecated in iOS 3.0 3.设置按钮图片 adjustsImageWhenHighlighted property // 确定当按钮高亮时图片是否改变的BOOL值,为真时图片随按钮高亮而高亮 adjustsImageWhenDisabled property // 确定当按钮高亮时图片是否改变的BOOL值,为真时图片随按钮失效而变暗 showsTouchWhenHighlighted property // 控制当按钮按下时是否闪光的BOOL值.默认NO,YES时按下会有白色光点.图片和按钮事件的不会因闪光改变. – backgroundImageForState: // 返回某个按钮状态下使用的背景图片. – imageForState: // 返回某个状态下的按钮图片. – setBackgroundImage:forState: // 设置特定状态的背景图片,默认都是normal – setImage:forState: // 设置特定状态的图片,默认都是normal 4.设置边界距离 contentEdgeInsets property // 按钮content内外线边缘绘制区域.content包含按钮图片和标题 Use this property to resize and reposition the effective drawing rectangle for the button content. The content comprises the button image and button title. You can specify a different value for each of the four insets (top, left, bottom, right). A positive value shrinks, or insets, that edge—moving it closer to the center of the button. A negative value expands, or outsets, that edge. Use the UIEdgeInsetsMake function to c*****truct a value for this property. The default value is UIEdgeInsetsZero. titleEdgeInsets property // 按钮标题绘制区域控制. Use this property to resize and reposition the effective drawing rectangle for the button title. You can specify a different value for each of the four insets (top, left, bottom, right). A positive value shrinks, or insets, that edge—moving it closer to the center of the button. A negative value expands, or outsets, that edge. Use the UIEdgeInsetsMake function to c*****truct a value for this property. The default value is UIEdgeInsetsZero. imageEdgeInsets property // 图片绘制偏移区域控制. Use this property to resize and reposition the effective drawing rectangle for the button image. You can specify a different value for each of the four insets (top, left, bottom, right). A positive value shrinks, or insets, that edge—moving it closer to the center of the button. A negative value expands, or outsets, that edge. Use the UIEdgeInsetsMake function to c*****truct a value for this property. The default value is UIEdgeInsetsZero. 5.得到当前状态 currentTitle property // 当前按钮上显示的标题(只读),当按钮状态改变时值自动改变.值可以为nil. currentTitleColor property // 当前标题颜色(只读).此值要保证不为nil,默认是白色. currentTitleShadowColor property // 标题的阴影颜色(只读).默认是白色. currentImage property // 当前按钮上的图片(只读).可以是nil. currentBackgroundImage property // 当前按钮背景图片(只读).可以是nil. imageView property // 按钮上的图片视图(只读).虽然它是只读的,但是他的属性是可读写的.imageView的属性在按钮还没有显示前就有值了.系统按钮这些值是nil 6.得到尺寸 – backgroundRectForBounds: // 返回背景绘制区域. – contentRectForBounds: // 返回内容绘制区域.内容区域是显示图片和标题及他们特定对齐缩放等的范围. – titleRectForContentRect: // 返回标题的绘制区域. – imageRectForContentRect: // 返回图片的绘制区域. 7.其他 按钮种类 typedef enum { UIButtonTypeCustom = 0, // 没有风格 UIButtonTypeRoundedRect, // 圆角风格按钮 UIButtonTypeDetailDisclosure, // UIButtonTypeInfoLight, // 明亮背景的信息按钮 UIButtonTypeInfoDark, // 黑暗背景的信息按钮 UIButtonTypeContactAdd, // } UIButtonType; 按钮状态: UIControlEventTouchDown // 按下 UIControlEventTouchDownRepeat // 多次按下 UIControlEventTouchDragInside // 保持按下然后在按钮及其一定的外围拖动 UIControlEventTouchDragOutside // 保持按下,在按钮外面拖动 UIControlEventTouchDragEnter // DragOutside进入DragInside触发 UIControlEventTouchDragExit // in到out触发 UIControlEventTouchUpInside // 在按钮及其一定外围内松开 UIControlEventTouchUpOutside // 按钮外面松开 UIControlEventTouchCancel // 点击取消 |