一、目錄
- 1.如何實(shí)現(xiàn)圓角 處理方案
- 2.上圖下文按鈕:自定義按鈕
二、如何實(shí)現(xiàn)圓角

Snip20150902_75.png
1. 方案一:設(shè)置按鈕的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 設(shè)置

Snip20150902_85.png
2、自定義按鈕

Snip20151027_3.png
- 方案一:在自定義按鈕的layoutSubviews方法中,調(diào)整按鈕子控件imageView/titleLabel的位置
- (void)awakeFromNib
{
self.titleLabel.textAlignment = NSTextAlignmentCenter;
}
- (void)layoutSubviews
{
[super layoutSubviews];
// 調(diào)整圖片的位置和尺寸
self.imageView.y = 0;
self.imageView.centerX = self.width * 0.5;
// 調(diào)整文字的位置和尺寸
self.titleLabel.x = 0;
self.titleLabel.y = self.imageView.height;
self.titleLabel.width = self.width;
self.titleLabel.height = self.height - self.titleLabel.y;
}
方案二:重寫自定義按鈕的兩個(gè)方法,imageRect.... / titleRect......方法調(diào)整兩個(gè)子控件的frame布局子控件
方案三:當(dāng)然我們也可以在initWithFrame或者awakeFromNib來調(diào)整imageView/titleLabel兩個(gè)子控件的內(nèi)邊距,來調(diào)整它們自己的布局