Objective-C边框下的背景色神器
Objective-C background colour artifact under the border
我想创建一个这样的圆形按钮:
使用
UIButton *reportButton = [[UIButton alloc] initWithFrame:CGRectMake(200, -15, 30, 30)];
reportButton.backgroundColor = [UIColor whiteColor];
reportButton.layer.borderWidth = 2;
reportButton.layer.cornerRadius = reportButton.frame.size.width / 2;
reportButton.layer.borderColor = myRectangleBackgroundColor.CGColor;
但如您所见,按钮下方有一条 1px 宽的小圆线。
你可以在这张截图中看得更清楚:
如何让它消失?
1) 在 Core Graphics 中生成一个圆和另一个重叠的圆。
2) 从中创建一个 UIImage。
3) 将其设置为各种按钮状态的背景图像。
我用两个视图解决了它。一个30x30
的绿色UIView
和一个26x26
的白色UIButton
在里面。现在看起来像这样:
我想创建一个这样的圆形按钮:
使用
UIButton *reportButton = [[UIButton alloc] initWithFrame:CGRectMake(200, -15, 30, 30)];
reportButton.backgroundColor = [UIColor whiteColor];
reportButton.layer.borderWidth = 2;
reportButton.layer.cornerRadius = reportButton.frame.size.width / 2;
reportButton.layer.borderColor = myRectangleBackgroundColor.CGColor;
但如您所见,按钮下方有一条 1px 宽的小圆线。
你可以在这张截图中看得更清楚:
如何让它消失?
1) 在 Core Graphics 中生成一个圆和另一个重叠的圆。
2) 从中创建一个 UIImage。
3) 将其设置为各种按钮状态的背景图像。
我用两个视图解决了它。一个30x30
的绿色UIView
和一个26x26
的白色UIButton
在里面。现在看起来像这样: