[_btn1.layersetMasksToBounds:YES];
[_btn1.layersetCornerRadius:3.0];//设置矩圆角半径
[_btn1.layersetBorderWidth:1.0]; //边框宽度
CGColorSpaceRef colorSpace =CGColorSpaceCreateDeviceRGB();
CGColorRef colorref = CGColorCreate(colorSpace,(CGFloat[]){ 217/255.0, 217/255.0, 217/255.0, 1 });
[_btn1.layersetBorderColor:colorref];//边框颜色
--------------------------------------------------------------------
//单边边框(右边)
CALayer *deleteBtnBorder = [CALayer layer];
float height=self.deleteBtn.height;
float width=self.deleteBtn.width;
deleteBtnBorder.frame = CGRectMake(width, 0, 1, height);
deleteBtnBorder.backgroundColor = [UIColor redColor].CGColor;
[self.deleteBtn.layer addSublayer:deleteBtnBorder];
链接:http://www.zhihu.com/question/21710875/answer/21738384
如果只是简单地加一个边框的话,可以这样:
UIButton *yourButton = [UIButton buttonWithType:UIButtonTypeSystem];
// 初始化工作,设置文字,frame等等,略
// 按钮边框宽度
yourButton.layer.borderWidth = 1.5;
// 设置圆角
yourButton.layer.cornerRadius = 4.5;
// 设置颜色空间为rgb,用于生成ColorRef
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
// 新建一个红色的ColorRef,用于设置边框(四个数字分别是 r, g, b, alpha)
CGColorRef borderColorRef = CGColorCreate(colorSpace,(CGFloat[]){ 1, 0, 0, 1 });
// 设置边框颜色
yourButton.start.layer.borderColor = borderColorRef;
另外,这里有一个精彩的例子,推荐一下:
http://code4app.com/ios/UIButton-Bootstrap/52635e8c6803fa576b000000