IOS(二)基本控制項UIButton、簡易動畫

來源:互聯網
上載者:User

標籤:

UIButton

1 //1.設定UIButton 的左右移動2  .center屬性 獲得 CGPoint 來修改x y3 //1.設定UIButton 的放大縮小4   bounds屬性 獲得CGRect 然後通過size.height設定高 wight設定寬
//3.或者使用frame 來設定空間的 移動以及大小

代碼建立一個UIButton

 1     // 1.建立一個按鈕 2     UIButton *btn = [[UIButton alloc] init]; 3      4     // 2.添加按鈕 5     [self.view addSubview:btn]; 6      7     // 3.設定按鈕的frame 8     btn.frame = CGRectMake(100, 100, 100, 100); 9     10     // 4.給按鈕的預設狀態和高亮狀態設定背景圖片11     [btn setBackgroundImage:[UIImage imageNamed:@"btn_01"] forState:UIControlStateNormal];12     [btn setBackgroundImage:[UIImage imageNamed:@"btn_02"] forState:UIControlStateHighlighted];13     14     // 5.給按鈕的預設狀態和高亮狀態分別設定文字和文字的顏色15     [btn setTitle:@"點我啊" forState:UIControlStateNormal];16     [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];17     18     [btn setTitle:@"摸我幹啥" forState:UIControlStateHighlighted];19     [btn setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];20 21     // 6.給按鈕添加一個點擊事件,監控按鈕的點擊22     [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];23 24 25 26 - (void)btnClick:(UIButton *)btn27 {28     NSLog(@"btnClick");29 }

簡易動畫

 1 //簡易動畫的建立有兩種方式 2 //1.頭尾式 3     [UIView beginAnimations : nil context:nil];//開啟動畫 4     [UIView setAnimationDuration:1];//設定動畫執行時間 5             //這裡寫入需要執行動畫的代碼 6     [UIView commitAnimations];//提交動畫 7  8 //2.Block式 9     [UIView animateWithDuration: 0.5 animations:^{10 11            //這裡寫入一個需要執行的動畫代碼12     }];

 

IOS(二)基本控制項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.