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 // 點擊取消 |