ios11--UIButton

來源:互聯網
上載者:User

標籤:with   icon   背景圖   title   ram   touch   1.4   cti   gen   

////  ViewController.m//  02-UIButton(在代碼中使用)//#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    // 1.1 建立按鈕對象//    UIButton *button = [[UIButton alloc] init];    // 注意:設定按鈕的類型只能在初始化的時候設定  -> UIButtonTypeCustom    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];        // 1.2 設定按鈕的類型,是一個枚舉,    //button.buttonType = UIButtonTypeInfoDark;        // 1.3 設定frame    button.frame = CGRectMake(100, 100, 170, 60);        // 1.4 設定背景顏色//    button.backgroundColor = [UIColor redColor];//    [button setBackgroundColor:[UIColor redColor]];        // 1.5 設定文字    // 分狀態的://    button.titleLabel.text = @"普通文字"; 顯示不出來    [button setTitle:@"普通按鈕" forState:UIControlStateNormal];  //正常顯示的文字    [button setTitle:@"高亮按鈕" forState:UIControlStateHighlighted];//點擊時的文字        // 1.6 設定文字的顏色    [button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];    [button setTitleColor:[UIColor yellowColor] forState:UIControlStateHighlighted];        // 1.7 設定文字的陰影顏色    [button setTitleShadowColor:[UIColor blackColor] forState:UIControlStateNormal];    [button setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateHighlighted];        button.titleLabel.shadowOffset = CGSizeMake(3, 2);        // 1.8 設定內容圖片,圖片拖到Assets.xcassets右邊裡面去,    [button setImage:[UIImage imageNamed:@"player_btn_pause_normal"] forState:UIControlStateNormal];    [button setImage:[UIImage imageNamed:@"player_btn_pause_highlight"] forState:UIControlStateHighlighted];        button.imageView.backgroundColor = [UIColor purpleColor];        // 1.9 設定背景圖片    [button setBackgroundImage:[UIImage imageNamed:@"buttongreen"] forState:UIControlStateNormal];    [button setBackgroundImage:[UIImage imageNamed:@"buttongreen_highlighted"] forState:UIControlStateHighlighted];        // 2.0 加到控制器的view中    [self.view addSubview:button];        // 非常重要    /**     *  監聽按鈕的點擊事件,     *  Target: 目標 (讓誰做事情)     *  action: 方法 (做什麼事情-->方法)     *  Events: 事件     *///    SEL sel = @selector(clickButton:);    [button addTarget:self action:@selector(demo:) forControlEvents:UIControlEventTouchUpInside];}- (void)demo:(UIButton *)btn{//btn就是按鈕,    NSLog(@"%@", btn);}- (IBAction)clickButton:(UIButton *)button {    button.enabled = NO;}@end

 

ios11--UIButton

相關關鍵詞:
相關文章

聯繫我們

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