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 construct 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 construct 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 construct 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 // 點擊取消
UIButton小結
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.