我有一个自定义按钮,我想让它的左上角看起来像普通的圆形矩形。在左上角创建自定义的圆角矩形按钮角点?
我发现代码,使各个角落轮:
_myButton.layer.cornerRadius = 8;
_myButton.layer.borderWidth = 0.5;
_myButton.layer.borderColor = [UIColor grayColor].CGColor;
_myButton.clipsToBounds = YES;
我怎样才能修复代码,使之轮只是在左上方?
编辑:
_myButton.layer.borderWidth = 2;
_myButton.layer.borderColor = [UIColor blackColor].CGColor;
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_myButton.bounds
byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
cornerRadii:CGSizeMake(7.0, 7.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = _myButton.bounds;
maskLayer.path = maskPath.CGPath;
_myButton.layer.mask = maskLayer;
[maskLayer release];
此代码不能正常工作。整个按钮消失。
这里是你如何使用UIBezierPath告诉保留哪个角落/上一个UIView面具类似的提问/回答:http://stackoverflow.com/questions/10995226/how-to -ma-half-rounded-top-corner-rounded-texview-with-border – Brayden
我使用了那里提供的代码。但它不起作用。我将代码添加到问题的最后。你能帮我@布雷登吗? – Ali