iOS---设置btn边框和单边边框

    [_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


可以用view的layer属性来写的。

如果只是简单地加一个边框的话,可以这样:

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;


另外,这里有一个精彩的例子,推荐一下:

code4app.com/ios/UIButt


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值