UIButton设置为圆形按钮并增加边框

设置按钮的长和宽尺寸一致(即为正方形),然后将圆角半径设为边长的一半,即形成一个圆形

   UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
    btn.frame = CGRectMake(100, 100, 100, 100);
    
    // 设置按钮四个圆角的半径,默认为0,这里取边长一半便是一个圆
    btn.layer.cornerRadius = 50.0;
    // 设置边框的宽度
    btn.layer.borderWidth = 1.0;
    
    CGColorSpaceRef spaceRef = CGColorSpaceCreateDeviceRGB();
    CGColorRef colorRef = CGColorCreate(spaceRef, (CGFloat[]){255/255.0, 0/255.0, 0/255.0, 1});
    
    // 设置边框的颜色
    btn.layer.borderColor = colorRef;
    btn.backgroundColor = [UIColor lightGrayColor];
    [btn setTitle:@"Button" forState:UIControlStateNormal];

 

posted @ 2015-09-10 14:47  骑着蜗牛看雪  阅读(1656)  评论(0编辑  收藏  举报