iOS_UIButton 簡單操作

來源:互聯網
上載者:User

iOS_UIButton 簡單操作
UIButton 風格

typedef NS_ENUM(NSInteger, UIButtonType) {    UIButtonTypeCustom = 0,                         // no button type    UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0),  // standard system button    UIButtonTypeDetailDisclosure,    UIButtonTypeInfoLight,    UIButtonTypeInfoDark,    UIButtonTypeContactAdd,    UIButtonTypeRoundedRect = UIButtonTypeSystem,   // Deprecated, use UIButtonTypeSystem instead};
簡單操作
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];    button.tag = 100; // 給 Button 委任標記 在不同的方法中使用同一個控制項    button.frame = CGRectMake(30, 170, 200, 40);    [self.window addSubview:button];    // 設定按鈕文字,需要設定狀態    [button setTitle:@"按鈕" forState:UIControlStateNormal];//    [button setTitle:@"Hello" forState:UIControlStateHighlighted];    [button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; // 給字型設定顏色        button.showsTouchWhenHighlighted = YES; // 高亮    // 給button綁定事件    [button addTarget:self // 接受訊息的對象               action:@selector(buttonAction:) // 發送的訊息     forControlEvents:UIControlEventTouchUpInside]; // 觸發的方式
Button 方法
- (void) buttonAction{    NSLog(@"哢");    // 通過 tag ,從父類別檢視中擷取button    UIButton *btn = (UIButton *)[self.window viewWithTag:100];    [btn setTitle:@"點我" forState:UIControlStateNormal];    // 讓 Button 失效    [btn removeTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];}- (void) buttonAction:(UIButton *)sender{    sender.backgroundColor = [UIColor redColor];}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.