1.設(shè)置button的tag值
int k;
button.tag = k;
2.Button禁止觸摸事件的2種方式
//會(huì)改變按鈕的狀態(tài)来颤,顏色會(huì)變灰
button.enabled = NO;
//保持按鈕原來的狀態(tài)肴颊,顏色不會(huì)變
button.userInteractionEnabled = NO;
3.全部圓角/部分圓角
1.關(guān)鍵字:UIBezierPath
2.關(guān)鍵API:
+ (UIBezierPath *)bezierPathWithRoundedRect:(CGRect)rect byRoundingCorners:(UIRectCorner)corners cornerRadii:(CGSize)cornerRadii
3.關(guān)鍵詞組:
enum {
UIRectCornerTopLeft = 1 << 0,
UIRectCornerTopRight = 1 << 1,
UIRectCornerBottomLeft = 1 << 2,
UIRectCornerBottomRight = 1 << 3,
UIRectCornerAllCorners = ~0};
typedef NSUInteger UIRectCorner;
用法示例:
//初始話View
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(120, 10, 80, 80)];
view2.backgroundColor = [UIColor redColor];[self.view addSubview:view2];
//對(duì)View的左下角和右下角實(shí)現(xiàn)圓角效果
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view2.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = view2.bounds;
maskLayer.path = maskPath.CGPath;view2.layer.mask = maskLayer;
//實(shí)現(xiàn)四個(gè)角都有圓角效果
view2.layer.masksToBounds = YES;
view2.layer.cornerRadius = 5;
Button文本左對(duì)齊
無效寫法:
// button.titleLabel.textAlignment = NSTextAlignmentLeft;
NSTextAlignmentLeft針對(duì)UILabe有效
有效寫法:
//對(duì)齊方式修改為水平左對(duì)齊,但是會(huì)緊緊靠著左邊
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
//按鈕的內(nèi)容(控件)距離左邊20個(gè)像素,這樣就可以了
button.titleEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者