国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設(shè)計 > 正文

UIButton的基本用法

2019-11-09 18:01:05
字體:
供稿:網(wǎng)友

 第一、UIButton的定義

  UIButton *button=[[UIButton buttonWithType:(UIButtonType);

  能夠定義的button類型有以下6種,

  typedef enum {

  UIButtonTypeCustom = 0, 自定義風格

  UIButtonTypeRoundedRect, 圓角矩形

  UIButtonTypeDetailDisclosure, 藍色小箭頭按鈕,主要做詳細說明用

  UIButtonTypeInfoLight, 亮色感嘆號

  UIButtonTypeInfoDark, 暗色感嘆號

  UIButtonTypeContactAdd, 十字加號按鈕

  } UIButtonType;

  第二、設(shè)置frame

  button1.frame = CGRectMake(20, 20, 280, 40);

  [button setFrame:CGRectMake(20,20,50,50)];

  第三、button背景色

  button1.backgroundColor = [UIColor clearColor];

  [button setBackgroundColor:[UIColor blueColor]];

  第四、state狀態(tài)

  forState: 這個參數(shù)的作用是定義按鈕的文字或圖片在何種狀態(tài)下才會顯現(xiàn)

  enum {

  UIControlStateNormal = 0, 常規(guī)狀態(tài)顯現(xiàn)

  UIControlStateHighlighted = 1 << 0, 高亮狀態(tài)顯現(xiàn)

  UIControlStateDisabled = 1 << 1, 禁用的狀態(tài)才會顯現(xiàn)

  UIControlStateSelected = 1 << 2, 選中狀態(tài)

  UIControlStateApplication = 0x00FF0000, 當應用程序標志時

  UIControlStateReserved = 0xFF000000 為內(nèi)部框架預留,可以不管

  };

  @PRoperty(nonatomic,getter=isEnabled)BOOL enabled; // default is YES. if NO, ignores touch events and subclasses may draw differently

  @property(nonatomic,getter=isSelected)BOOL selected; // default is NO may be used by some subclasses or by application

  @property(nonatomic,getter=isHighlighted)BOOL highlighted;

  第五 、設(shè)置button填充圖片和背景圖片

  [buttonsetImage:[UIImageimageNamed:@"checkmarkControllerIcon"]forState:UIControlStateNormal];

  [buttonsetBackgroundImage:[UIImageimageNamed:@"checkmarkControllerIcon"]forState:UIControlStateNormal];

  第六、設(shè)置button標題和標題顏色

  [button1 setTitle:@"點擊" forState:UIControlStateNormal];

  [buttonsetTitleColor:[UIColorredColor]forState:UIControlStateNormal];

  第七、設(shè)置按鈕按下會發(fā)光

  button.showsTouchWhenHighlighted=NO;

  第八、添加或刪除事件處理

  [button1 addTarget:self action:@selector(butClick:) forControlEvents:UIControlEventTouchUpInside];

  [btn removeTarget:nil action:nil forControlEvents:UIControlEventTouchUpInside];

  第九、 設(shè)置按鈕內(nèi)部圖片間距和標題間距

  UIEdgeInsets insets; // 設(shè)置按鈕內(nèi)部圖片間距

  insets.top = insets.bottom = insets.right = insets.left = 10;

  bt.contentEdgeInsets = insets;

  bt.titleEdgeInsets = insets; // 標題間距

十、重寫繪制行為 你可以通過子類化按鈕來定制屬于你自己的按鈕類。在子類化的時候你可以重載下面這些方法,這些方法返回CGRect結(jié)構(gòu),指明了按鈕每一組成部分的邊界。注意:不要直接調(diào)用這些方法, 這些方法是你寫給系統(tǒng)調(diào)用的。 backgroundRectForBounds   //指定背景邊界  contentRectForBounds // 指定內(nèi)容邊界  titleRectForContentRect    // 指定文字標題邊界  imageRectForContentRect     //指定按鈕圖像邊界  例:- (CGRect)imageRectForContentRect:(CGRect)bounds{      return CGRectMake(0.0, 0.0, 44, 44);  


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 宿迁市| 灵山县| 塔河县| 手机| 隆化县| 社旗县| 仁怀市| 营口市| 惠来县| 集贤县| 长垣县| 大新县| 蒙山县| 天台县| 新野县| 城固县| 池州市| 秦皇岛市| 丰原市| 临泽县| 闸北区| 扎囊县| 黄龙县| 林西县| 梨树县| 尉氏县| 北安市| 东安县| 沅江市| 达州市| 仁寿县| 达尔| 日土县| 东至县| 桐梓县| 马龙县| 噶尔县| 西峡县| 寿阳县| 门源| 嘉定区|