UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0, 0, 80, 40);
[btn.layer setMasksToBounds:YES];
[btn.layer setCornerRadius:10.0]; //设置矩形四个圆角半径
[btn.layer setBorderWidth:5.0]; //边框宽度
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGColorRef colorref = CGColorCreate(colorSpace,(CGFloat[]){ 1, 0, 0, 1 });
[btn.layer setBorderColor:colorref];//边框颜色
[self.view addSubview:btn];
还可以设置CALayer的其它属性,详情查看CALayer帮助文档