美文网首页
oc设置圆角的3种方式

oc设置圆角的3种方式

作者: 北纬49度的雨 | 来源:发表于2018-03-05 18:06 被阅读0次

1.通过设置layer的属性

最简单的一种,但是很影响性能,一般在正常的开发中使用很少.

UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)]; //只需要设置layer层的两个属性

//设置圆角 imageView.layer.cornerRadius = imageView.frame.size.width / 2;

//将多余的部分切掉 imageView.layer.masksToBounds = YES;

[self.view addSubview:imageView];

2.使用贝塞尔曲线UIBezierPath和Core Graphics框架画出一个圆角

UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];

imageView.image = [UIImage imageNamed:@"1"];

//开始对imageView进行画图 UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 1.0);

//使用贝塞尔曲线画出一个圆形图 [[UIBezierPath bezierPathWithRoundedRect:imageView.bounds cornerRadius:imageView.frame.size.width] addClip];

[imageView drawRect:imageView.bounds];

imageView.image = UIGraphicsGetImageFromCurrentImageContext();

//结束画图

UIGraphicsEndImageContext();

[self.view addSubview:imageView];

3.使用CAShapeLayer和UIBezierPath设置圆角

 UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];

imageView.image = [UIImage imageNamed:@"1"];

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:imageView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomRight cornerRadii:imageView.bounds.size];

CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];

//设置大小

maskLayer.frame = imageView.bounds;

//设置形状

maskLayer.path = maskPath.CGPath;

imageView.layer.mask = maskLayer;

[self.view addSubview:imageView]; }

这三种方法中第三种最好,对内存的消耗最少啊,而且渲染快速。

相关文章

  • 2018-09-07

    oc 圆角阴影设置 View.backgroundColor = [UIColor whiteColor]; Vi...

  • oc设置圆角的3种方式

    1.通过设置layer的属性 最简单的一种,但是很影响性能,一般在正常的开发中使用很少. UIImageView ...

  • 边框效果-css-v1.0.0

    半透边框 通过设置颜色的透明度实现。 框内圆角 方式1:为元素设置圆角,外层设置轮廓outline。圆角与直角之间...

  • Xib中设置控件的圆角、边框效果

    xib中为各种控件设置圆角 通过代码的方式设置 通过xib快速设置圆角利用User Defined Runtime...

  • Flutter知识点总结一

    一、设置图片的圆角 由于图片不能直接设置圆角,所以我们需要采用其它方式来设置: 1、使用ClipRRect进行设置...

  • Android圆角背景设置

    一、前言: 使用databinding设置圆角背景,代替drawable方式 1、xml中设置圆角背景 注意:这个...

  • 设置圆角的方式

  • 圆角与阴影

    1. 画圆角 (1)传统的圆角设置方式 imageView.clipsToBounds = YES; imag...

  • iOS-UIImageView圆角设置

    iOS开发中图片圆角设置是最常见的需求,圆角符合人类视觉安全体验,让人感觉舒适,设置圆角也是非常简单,有五种方式来...

  • CALayer常用属性整理(三)

    圆角与阴影 单纯的圆角应该没什么可说的。网上有很多设置圆角的方式。比如最简单的layer.cornerRadius...

网友评论

      本文标题:oc设置圆角的3种方式

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