设置UI控件的Layer属性(边框可见,边框颜色,边框宽度,边框圆角)

设置UI控件的Layer属性

#import "ViewController.h"

@interface ViewController ()

@property (strong, nonatomic) IBOutlet UIButton *btnSave;

@property (strong, nonatomic) IBOutlet UIView *yellowView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //获取button的图层
    CALayer *layer = self.btnSave.layer;
    //设置button图层的边框可见(只有masks遮住bounds,这样bounds才可见,否则都是透明的)
    layer.masksToBounds = YES;
    //设置button图层的边框颜色
    layer.borderColor = [UIColor redColor].CGColor;
    //设置button图层的边框宽度
    layer.borderWidth = 2;
    
    //设置button图层的角度半径
    layer.cornerRadius = 10.0;
    
    
    self.yellowView.layer.masksToBounds = YES;
    self.yellowView.layer.borderColor = [UIColor blueColor].CGColor;
    
}

posted @ 2016-02-26 10:32  stevenwuzheng  阅读(6437)  评论(0编辑  收藏  举报