iOS --按鈕 處理
一、目錄
- 1.如何實現圓角 處理方案
- 2.上圖下文按鈕:自定義按鈕
二、如何實現圓角
![831339-4435d7977304db06.png](https://i.iter01.com/images/39da115249467538a2c257be4021a36e89cbe6746cce917368c84734389d33a3.png)
Snip20150902_75.png
1. 方案一:設定按鈕的layer屬性
self.loginButton.layer.cornerRadius = 5;
self.loginButton.layer.masksToBounds = YES; // 裁剪
2. 方案二:KVC 修改 layer屬性
[self.loginButton setValue:@5 forKeyPath:@"layer.cornerRadius"];
[self.loginButton setValue:@YES forKeyPath:@"layer.masksToBounds"];
3. 方案三:通過storyboard / xib 設定
![831339-a2c5d00e26015dd8.png](https://i.iter01.com/images/89cb630a5a7412d1f353ac48f8332c0a4b742eb21e84320695821ea4813f4133.png)
Snip20150902_85.png
2、自定義按鈕
![831339-09ebdb56d759223b.png](https://i.iter01.com/images/6a45cb21795259b5585e08e14cf745ae38ff5dbc33b611173063bdf1cb4f1b31.png)
Snip20151027_3.png
- 方案一:在自定義按鈕的layoutSubviews方法中,調整按鈕子控制元件imageView/titleLabel的位置
- (void)awakeFromNib
{
self.titleLabel.textAlignment = NSTextAlignmentCenter;
}
- (void)layoutSubviews
{
[super layoutSubviews];
// 調整圖片的位置和尺寸
self.imageView.y = 0;
self.imageView.centerX = self.width * 0.5;
// 調整文字的位置和尺寸
self.titleLabel.x = 0;
self.titleLabel.y = self.imageView.height;
self.titleLabel.width = self.width;
self.titleLabel.height = self.height - self.titleLabel.y;
}
方案二:重寫自定義按鈕的兩個方法,imageRect.... / titleRect......方法調整兩個子控制元件的frame佈局子控制元件
方案三:當然我們也可以在initWithFrame或者awakeFromNib來調整imageView/titleLabel兩個子控制元件的內邊距,來調整它們自己的佈局
相關文章
- Android處理按鈕重複點選Android
- 異形按鈕的點選區域處理
- Android優雅地處理按鈕重複點選Android
- iOS 自定義鍵盤字母按鈕iOS
- iOS 左滑按鈕(UITableViewRowAction)顯示圖片iOSUIView
- iOS Tabbar中間新增凸起可旋轉按鈕iOStabBar
- iOS 11開發教程(二十一)iOS11應用檢視美化按鈕之實現按鈕的響應(1)iOS
- Fiori Elements List Report table 裡的普通按鈕,Global 按鈕 和 Determining 按鈕
- 高亮按鈕
- iOS - 新增一個全域性懸浮按鈕(整合pods版)iOS
- Jquery實現的Switch開關按鈕(仿iOS開關)jQueryiOS
- iOS image處理BlendModesiOS
- Flutter Button(按鈕)Flutter
- 小程式按鈕
- 復飛按鈕
- 分析微信(iOS 版)定製導航欄按鈕的思路iOS
- iOS 中多音訊處理iOS音訊
- HTML input image 按鈕HTML
- HTML input button 按鈕HTML
- HTML input image按鈕HTML
- HTML input button按鈕HTML
- vue 封裝按鈕Vue封裝
- VBA命令按鈕操作
- 瞭解下Foundation 按鈕
- iOS開發:給UIWebview的導航欄新增返回、關閉按鈕iOSUIWebView
- Qt更改按鈕樣式 (以QSpinBox使用左右按鈕樣式為例)QT
- 乾貨!必看創意按鈕設計,打造真正的按鈕誘惑
- 記錄:iOS10 storyboard的帶有計時器功能的按鈕。iOS
- JFrame容器和JButton按鈕
- flutter demo (二):禁用按鈕Flutter
- 單選多選按鈕
- [JS]bootstrapTable新增操作按鈕JSbootAPT
- HTML input reset 重置按鈕HTML
- Python文字框與按鈕Python
- Tkinter (02) 按鈕部件 Button
- LabVIEW的自定義按鈕View
- 按鈕式超連結
- 瞭解下Foundation 按鈕組
- MFC 捕獲按鈕 按下和抬起 (轉)