iOS學習筆記(七)——UI基礎UIButton

來源:互聯網
上載者:User

 

  UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(60, 60, 200, 60)];    btn.backgroundColor=[UIColor greenColor];    [btn setTitle:@"btn1" forState:UIControlStateNormal];    [self.view addSubview:btn];

 

 

 

UIButton *btn2=[UIButton buttonWithType:UIButtonTypeRoundedRect];    CGRect rect=CGRectMake(60, 160, 200, 60);    btn2.frame=rect;    btn2.tag=1001;    btn2.backgroundColor=[UIColor colorWithRed:30/255.0 green:200/255.0 blue:125/255.0 alpha:1.0];    [btn2 setTitle:@"btn2" forState:UIControlStateNormal];    [btn2 addTarget:self action:@selector(btn2Pressed) forControlEvents:UIControlEventTouchDown];    [self.view addSubview:btn2];

btn2Pressed方法:

 

 

-(void)btn2Pressed{    NSLog(@"button pressed");}

 

typedef enum {    UIButtonTypeCustom = 0,           // no button type   自訂,無風格    UIButtonTypeRoundedRect,          // rounded rect, flat white button, like in address card 白色圓角矩形,類似喜好設定表格單元或者地址簿卡片    UIButtonTypeDetailDisclosure,//藍色的披露按鈕,可放在任何文字旁    UIButtonTypeInfoLight,//微件(widget)使用的小圓圈資訊按鈕,可以放在任何文字旁    UIButtonTypeInfoDark,//白色背景下使用的深色圓圈資訊按鈕    UIButtonTypeContactAdd,//藍色加號(+)按鈕,可以放在任何文字旁} UIButtonType;

void)setTitle:(NSString *)title forState:(UIControlState)state;  

          

void)setTitleColor:(UIColor *)color forState:(UIControlState)state;   

            

void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state;          


void)setImage:(UIImage *)image forState:(UIControlState)state;        


void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state;    

 

typedef NS_OPTIONS(NSUInteger, UIControlState) {    UIControlStateNormal       = 0,    UIControlStateHighlighted  = 1 << 0,                  // used when UIControl isHighlighted is set    UIControlStateDisabled     = 1 << 1,    UIControlStateSelected     = 1 << 2,                  // flag usable by app (see below)    UIControlStateApplication  = 0x00FF0000,              // additional flags available for application use    UIControlStateReserved     = 0xFF000000               // flags reserved for internal framework use};



 

 

 

[btn addTarget:<#(id)#> action:<#(SEL)#> forControlEvents:<#(UIControlEvents)#>]


 

 

typedef NS_OPTIONS(NSUInteger, UIControlEvents) {    UIControlEventTouchDown           = 1 <<  0,      // on all touch downs    UIControlEventTouchDownRepeat     = 1 <<  1,      // on multiple touchdowns (tap count > 1)    UIControlEventTouchDragInside     = 1 <<  2,    UIControlEventTouchDragOutside    = 1 <<  3,    UIControlEventTouchDragEnter      = 1 <<  4,    UIControlEventTouchDragExit       = 1 <<  5,    UIControlEventTouchUpInside       = 1 <<  6,    UIControlEventTouchUpOutside      = 1 <<  7,    UIControlEventTouchCancel         = 1 <<  8,    UIControlEventValueChanged        = 1 << 12,     // sliders, etc.    UIControlEventEditingDidBegin     = 1 << 16,     // UITextField    UIControlEventEditingChanged      = 1 << 17,    UIControlEventEditingDidEnd       = 1 << 18,    UIControlEventEditingDidEndOnExit = 1 << 19,     // 'return key' ending editing    UIControlEventAllTouchEvents      = 0x00000FFF,  // for touch events    UIControlEventAllEditingEvents    = 0x000F0000,  // for UITextField    UIControlEventApplicationReserved = 0x0F000000,  // range available for application use    UIControlEventSystemReserved      = 0xF0000000,  // range reserved for internal framework use    UIControlEventAllEvents           = 0xFFFFFFFF};



 

 


@張興業TBOW

 

 

 

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIButton_Class/UIButton/UIButton.html

 

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIKit_Framework/Introduction/Introduction.html#//apple_ref/doc/uid/TP40006955-CH1-SW1

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.