简体   繁体   English

给定拐角半径时,UIButton边框被剪切

[英]UIButton border cut when corner radius is given

I have created the UIButton with specific position corner radius means left button have top left and bottom left corner radius and right button have top right and bottom right corner radius i have take the button in Xib and give border but i cut from some side i have attach the screenshot below. 我创建了具有特定位置拐角半径的UIButton,这意味着左按钮具有左上角和左下角半径,右按钮具有右上角和右下角半径我在Xib中采用了按钮并给出了边框,但是我从某个侧面切开了附上下面的截图。 在此处输入图片说明

Look at right side corner border cut. 看右下角边框切。 here is my code 这是我的代码

  [btn_Newest setBackgroundColor:RGB(28.0, 91.0, 161.0, 1.0)];
    [btn_Newest.layer setBorderWidth:1.5];
    [btn_Newest.layer setBorderColor:RGB(28.0, 91.0, 161.0, 1.0).CGColor];
    [btn_Newest setClipsToBounds:YES];
    btn_Newest = (UIButton *)[self setroundCornersOnView:btn_Newest onTopLeft:YES topRight:NO bottomLeft:YES bottomRight:NO radius:7.0];


    [btn_Popular setBackgroundColor:viewTopBar.backgroundColor];
    [btn_Popular.layer setBorderWidth:1.5];
    [btn_Popular.layer setBorderColor:RGB(28.0, 91.0, 161.0, 1.0).CGColor];
    [btn_Popular setClipsToBounds:YES];
    btn_Popular = (UIButton *)[self setroundCornersOnView:btn_Popular onTopLeft:NO topRight:YES bottomLeft:NO bottomRight:YES radius:7.0];

setroundCornersOnView this function create specific side corner radius.Can any one help me in this situation. setroundCornersOnView此函数创建特定的边角半径。在这种情况下,任何人都可以帮帮我。

Kindly try the following code. 请尝试以下代码。 i think it will satisfy your requirements. 我认为它将满足您的要求。

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:btnPush.bounds byRoundingCorners:(UIRectCornerTopRight | UIRectCornerBottomRight) cornerRadii:CGSizeMake(7.0, 7.0)];

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.view.bounds;
maskLayer.path  = maskPath.CGPath;
btnPush.layer.mask = maskLayer;

CAShapeLayer *borderLayer = [[CAShapeLayer alloc] init];
borderLayer.frame = self.view.bounds;
borderLayer.path  = maskPath.CGPath;
borderLayer.lineWidth   = 1.5f;
borderLayer.strokeColor = [UIColor blackColor].CGColor;
borderLayer.fillColor   = [UIColor clearColor].CGColor;
[btnPush.layer addSublayer:borderLayer];

Output : 输出:

在此处输入图片说明

Instead of setting setroundCornersOnView .You can set cornerRadius to the button. 您可以将cornerRadius设置为按钮,而不是设置setroundCornersOnView。 try below code. 尝试下面的代码。 [btn_Newest.layer setCornerRadius:5];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM