【问题标题】:image corner radius only bottom left and right图像角半径仅左下角和右下角
【发布时间】:2016-06-08 01:07:27
【问题描述】:

我想将圆角半径精确地设置为圆形,仅左下角和右下角。我已经完成了,但是底部的形状看起来不像是圆形的,所以我该如何解决这个问题

【问题讨论】:

  • 查看下面的链接 Link1 , Link2
  • 查看这个链接stackoverflow.com/questions/10167266/…也许对你有帮助。
  • UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.imageView.bounds byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight)cornerRadii:CGSizeMake(10.0, 10.0)]; CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; maskLayer.frame = self.imageView.bounds; maskLayer.path = maskPath.CGPath; self.imageView.layer.mask = maskLayer;
  • 我使用了那个代码,但不是圆形的底部..看看我在底部的图像
  • 当这段代码在 iphone6 imageview 上运行时,在正确的位置留下了一些宽度空间..

标签: ios objective-c


【解决方案1】:

我有同样的问题,我是这样解决的:

- (void)setMaskTo:(UIView*)view {
CAShapeLayer *rect = [[CAShapeLayer alloc] init];
[rect setFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height/2)];
rect.backgroundColor = ([UIColor grayColor]).CGColor;

UIBezierPath *shape = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0,rect.frame.size.height/2,self.view.frame.size.width,self.view.frame.size.height/2)];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = shape.CGPath;
shapeLayer.fillColor = [UIColor grayColor].CGColor;

CAShapeLayer *viewMask = [[CAShapeLayer alloc] init];
[viewMask addSublayer:shapeLayer];
[viewMask addSublayer:rect];

view.layer.mask = viewMask;
}

【讨论】:

    【解决方案2】:
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.imageView.bounds byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(10.0, 10.0)];
    
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.imageView.bounds;
    maskLayer.path  = maskPath.CGPath;
    self.imageView.layer.mask = maskLayer;
    

    【讨论】:

    • 好的,我使用了您的代码并提供了 CGSizeMake(150.0, 150.0)] 但结果相同,在底部看我的图像不是完全圆形,当此代码在 iphone 6 中运行时,宽度和高度相同,它需要一些宽度空间。
    猜你喜欢
    • 1970-01-01
    • 2017-01-18
    • 1970-01-01
    • 2013-12-22
    • 2020-10-27
    • 2015-09-22
    • 1970-01-01
    • 2021-08-21
    • 2017-05-13
    相关资源
    最近更新 更多