UIButton的圆角

Posted fantasy3588

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UIButton的圆角相关的知识,希望对你有一定的参考价值。

_interestedBtn = [UIButton buttonWithType:UIButtonTypeCustom];

    _interestedBtn.layer.cornerRadius = 8;

    _interestedBtn.layer.borderColor = [UIColor orangeColor].CGColor;

    _interestedBtn.layer.borderWidth = 1;

    _interestedBtn.layer.masksToBounds = YES;

    [_interestedBtn setTitle:@"感兴趣" forState:UIControlStateNormal];

    [_interestedBtn setTitle:@"已感兴趣" forState:UIControlStateSelected];

    [_interestedBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];

    [_interestedBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateSelected];

    [_interestedBtn addTarget:self action:@selector(interestedBtnAction:) forControlEvents:UIControlEventTouchUpInside];

    [self.contentView addSubview:_interestedBtn];

 

-(void)interestedBtnAction:(UIButton *)sender{

    sender.selected = !sender.selected;

    

    if (sender.selected) {

        _interestedBtn.layer.cornerRadius = 8;

        _interestedBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;

        _interestedBtn.layer.borderWidth = 1;

        _interestedBtn.layer.masksToBounds = YES;

    }else{

        _interestedBtn.layer.cornerRadius = 8;

        _interestedBtn.layer.borderColor = [UIColor orangeColor].CGColor;

        _interestedBtn.layer.borderWidth = 1;

        _interestedBtn.layer.masksToBounds = YES;

    }

}

以上是关于UIButton的圆角的主要内容,如果未能解决你的问题,请参考以下文章

模糊的圆角矩形 UIBezierPath,UIButton 背景

UIButton圆角时为啥会有粗糙的黑边?

在带有圆角的 UIButton 中添加底部边框

UIButton中的UIBezierPath圆角

自定义 UIButton 圆角

UIButton 圆角半径在 CustomClass 中无法正常工作