- --------按鈕
- backgroundImage 按鈕有多大, 圖片就會顯示多大
- image 圖片有多大, 按鈕就會被撐到圖片的大小
- 如果同時設置了 tile backgroundImage : 文字 顯示到 圖片的正上方
- 如果同時設置了 title image : 圖片在左側, 文字在右側
- 如果設置 button 的 title , image , backgroundImage 的時候, 一定要分狀態設置
- 兩種動畫方式
- 1. 首尾式動畫
- // 開始動畫
- [UIView beginAnimations:nil context:nil];
- // 執行動畫的操作
- // Duration 持續時間
- #warning 要放到執行動畫操作代碼的前面纔會生效
- [UIView setAnimationDuration:0.5];
- self.zbButton.frame = tempFrame;
- // 提交動畫
- [UIView commitAnimations];
- 2. block 動畫 (重點掌握 block動畫) block在iOS中是常用的.
- [UIView animateWithDuration:0.5 animations:^{
- // 放置 執行動畫的操作
- self.zbButton.frame = tempFrame;
- }];
- button的實例化方式
- buttonWithType:
- initWithFrame: UI控件獨有的實例化方法
- init : 所有的對象 都具有的實例化方法
- 爲button設置背景圖片
- IImage *image = [UIImage imageNamed:@"btn_01"];
- [button setBackgroundImage:image forState:UIControlStateNormal];
- [button addTarget:self
- action:@selector(didClickButton:)
- forControlEvents:UIControlEventTouchUpInside];
- 這裏注意純代碼 : 可以很方便的做修改及調試 最好不要用SB
iOS 中button的用法
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.