第一、uibutton的定義
uibutton *button=[[uibutton buttonwithtype:(uibuttontype);
能夠定義的button型別有以下6種,
typedef enum uibuttontype;
第
二、設定frame
button1.frame = cgrectmake(20, 20, 280, 40);
[button setframe:cgrectmake(20,20,50,50)];
第三、button背景色
button1.backgroundcolor = [uicolor clearcolor];
[button setbackgroundcolor:[uicolorbluecolor]];
第四、state狀態
forstate: 這個引數的作用是定義按鈕的文字或在何種狀態下才會顯現
uicontrolstatereserved = 0xff000000 為內部框架預留,可以不管他
};@property(nonatomic,getter=isenabled)boolenabled; // default is yes. if no, ignores touch events and subclasses may draw differently
@property(nonatomic,getter=ishighlighted)bool highlighted;
第五 、設定button填充和背景
[buttonsetimage:[uiimageimagenamed:@"checkmarkcontrollericon"]forstate:uicontrolstatenormal];
[buttonsetbackgroundimage:[uiimageimagenamed:@"checkmarkcontrollericon"]forstate:uicontrolstatenormal];
第
六、設定button標題和標題顏色
[button1 settitle:@"點選" forstate:uicontrolstatenormal];
[buttonsettitlecolor:[uicolorredcolor]forstate:uicontrolstatenormal];
第七、設定按鈕按下會發光
button.showstouchwhenhighlighted=no;
第八、新增或刪除事件處理
[button1 addtarget:self action:@selector(butclick:) forcontrolevents:uicontroleventtouchupinside];
[btn removetarget:nil action:nil forcontrolevents:uicontroleventtouchupinside];
第九、 設定按鈕內部間距和標題間距
uiedgeinsets insets; // 設定按鈕內部間距
insets.top = insets.bottom = insets.right = insets.left = 10;
bt.contentedgeinsets = insets;
bt.titleedgeinsets = insets; // 標題間距
IOS UIButton用法詳解
這段 動態的建立了乙個uibutton,並且把相關常用的屬性都列舉了.希望對大家有用.注意 button1addtarget self action selector alarmtimedone forcontrolevents uicontroleventtouchupinside addtarg...
IOS UIButton用法詳解
注意 button1addtarget self action selector alarmtimedone forcontrolevents uicontroleventtouchupinside addtarget self 是鏈結到self,一般都這樣設定 action selector al...
IOS UIButton用法詳解
這段 動態的建立了乙個uibutton,並且把相關常用的屬性都列舉了.希望對大家有用.注意 button1addtarget self action selector alarmtimedone forcontrolevents uicontroleventtouchupinside addtarg...