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.

enter image description here

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top