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

   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];

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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-08
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-21
  • 2022-01-09
  • 2022-12-23
  • 2022-12-23
  • 2021-06-19
相关资源
相似解决方案