我试图设置UIButton的cornerRadius,但我不知道该怎么做.
如果我喜欢这样:
button.layer.cornerRadius = 5;
Run Code Online (Sandbox Code Playgroud)
效果很好,如果我这样做:
button.layer.cornerRadius = 5;
[button setBackgroundColor:[UIColor colorWithPatternImage:radialGradient]];
Run Code Online (Sandbox Code Playgroud)
角落不圆.
我知道我可以解决这个问题
[button.layer setMasksToBounds:YES];
Run Code Online (Sandbox Code Playgroud)
但我特意寻找不同的解决方案,因为我在按钮上添加了一些箭头,如果我将蒙版设置为边界,则箭头会被遮盖.
编辑:
radialGradient是whit func
+ (UIImage *)getRadialGradientImage:(CGSize)size centre:(CGPoint)centre radius:(float)radius startColor:(UIColor *)startColor endColor:(UIColor *)endColor{
// Initialise
UIGraphicsBeginImageContextWithOptions(size, YES, 1);
// Create the gradient's colours
size_t num_locations = 2;
CGFloat locations[2] = { 0.0, 1.0 };
const CGFloat *component_first = CGColorGetComponents([startColor CGColor]);
CGFloat red1 = component_first[0];
CGFloat green1 = component_first[1];
CGFloat blue1 = component_first[2];
const CGFloat *component_second = CGColorGetComponents([endColor CGColor]);
CGFloat red2 = component_second[0];
CGFloat green2 …Run Code Online (Sandbox Code Playgroud)