美文网首页
iOS中的圆角

iOS中的圆角

作者: 少少白 | 来源:发表于2016-04-13 20:11 被阅读146次

UIImageView的圆角:

  • 产生离屏渲染的maskToBounds
    cell.imageOne.layer.cornerRadius = 30.0;
    cell.imageOne.layer.masksToBounds = YES;
  • 添加maskView
    CALayer *maskLayer = [[CALayer alloc] init];
    maskLayer.frame = CGRectMake(0, 0, 60, 60);
    maskLayer.contents = (__bridge id _Nullable)([UIImage imageNamed:@"appIcon_placeholder"].CGImage);
    cell.imageOne.layer.mask = maskLayer; // iOS 7
    cell.imageTwo.maskView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"appIcon_placeholder"]]; // iOS 8
    cell.imageThree.maskView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"appIcon_placeholder"]];
  • 生成一张圆角图片
- (UIImage *)cornerWithImage:(UIImage *)image cornerRadius:(CGFloat)cornerRadius andSize:(CGSize)size
{
    CGRect rect = CGRectMake(0, 0, size.width, size.height);
    UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);
    CGContextRef contextRef = UIGraphicsGetCurrentContext();
    UIBezierPath  *bezierPath = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(cornerRadius, cornerRadius)];
    CGContextAddPath(contextRef, bezierPath.CGPath);
    CGContextClip(contextRef);
    [image drawInRect:rect];
    CGContextDrawPath(contextRef, kCGPathFillStroke);
    UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return resultImage;
}

Demo地址MyCornerRadius
参考:

相关文章

  • 视图指定位置圆角

    mark:iOS开发之指定UIView的某几个角为圆角ios中设置view固定方向的圆角 iOS View 指定圆...

  • iOS 圆角问题

    一般在iOS开发的过程中这样设置圆角 亲测在TableView 中一屏60个圆角, iOS 9.0 之后FPS能保...

  • iOS 绘制圆角

    级别: ★☆☆☆☆标签:「iOS切圆角」「layer圆角」「CAShapeLayer圆角」作者: Xs·H审校: ...

  • iOS中的圆角

    UIImageView的圆角: 产生离屏渲染的maskToBounds 添加maskView 生成一张圆角图片 D...

  • iOS高效添加圆角效果实战讲解

    iOS高效添加圆角效果实战讲解 iOS高效添加圆角效果实战讲解

  • iOS 常用组件-高效切圆角方法总结

    iOS 常用组件-高效切圆角方法总结 iOS 常用组件-高效切圆角方法总结

  • iOS设置圆角的四种方法

    原文iOS设置圆角的四种方法iOS设置圆角的方法及指定圆角的位置 一、设置CALayer的cornerRadius...

  • 关于UIView切圆角的两种方式

    在 iOS App 开发中,切圆角的场景有很多。很多图片或者 UIView 都需要切圆角。 切圆角的方式一般有两种...

  • iOS设置圆角之:离屏渲染的问题和解决

    iOS中实现UIView及其子类的圆角效果有2中方法 检测开启离屏渲染 实现圆角两部曲 设置圆角就一定会触发离屏渲...

  • 关于corner 性能问题

    在ios 中绘制圆角常用方式: 即可实现圆角; 如果需要只设置上边角或者下边角1个或者几个圆角,也可通过下面的方式...

网友评论

      本文标题:iOS中的圆角

      本文链接:https://www.haomeiwen.com/subject/okqglttx.html