I'm creating uiview button
'Button = [UIButton buttonWithType:UIButtonTypeCustom];
with color at selected state and normal state. The point is i want to change mask. To make my button with one side radius corners.
to do this I'm using metod:
- (void)cornerMaskRadiusAtButton:(UIButton*)button leftSide:(BOOL)side
{
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = button.bounds;
UIBezierPath *roundedPath;
if(side){
roundedPath =[UIBezierPath bezierPathWithRoundedRect:maskLayer.bounds
byRoundingCorners:UIRectCornerTopLeft |
UIRectCornerBottomLeft
cornerRadii:CGSizeMake(18.f, 18.f)];
}
else{
roundedPath = [UIBezierPath bezierPathWithRoundedRect:maskLayer.bounds
byRoundingCorners:UIRectCornerTopRight |
UIRectCornerBottomRight
cornerRadii:CGSizeMake(18.f, 18.f)];
}
maskLayer.path = [roundedPath CGPath];
button.layer.mask = maskLayer;
}
but the result is like this:
after I call this metods:
[self cornerMaskRadiusAtButton:Button leftSide:NO];
Button.layer.borderColor = [UIColor whiteColor].CGColor;
Button.layer.borderWidth = 1.;
but the the border is wrong.
How to fix the border line ?
U will not see your layer border beacouse u are cuting off it with ur layer mask. It's why u see only fragment of it and other not. They are cut.
The best way to do it is to creat a graphic for the buttons and replace bacgroundimage for example:
icon = [UIImage imageNamed:@"name"];
[Button setBackgroundImage:icon forState:UIControlStateNormal];
U can set for other state to like: UIControlStateSelected some other image.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.