iOS设置圆角的三种方式
第一种方法:通过设置layer的属性
最简单的一种,但是很影响性能,一般在正常的开发中使用很少.
1
2
3
4
5
6
7
|
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]; |
第二种方法:使用贝塞尔曲线UIBezierPath和Core Graphics框架画出一个圆角
1
2
3
4
5
6
7
8
9
10
11
|
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]; |
第三种方法:使用CAShapeLayer和UIBezierPath设置圆角
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
@interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(, , , )];
imageView.image = [UIImage imageNamed:@""];
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:imageView.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(, )];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
maskLayer.frame = imageView.bounds;
maskLayer.path = maskPath.CGPath;
imageView.layer.mask = maskLayer;
[self.view addSubview:imageView];
}
这三种方法中第三种最好,对内存的消耗最少啊,而且渲染快速。
效果图:
iOS设置圆角的三种方式的更多相关文章
- iOS拨打电话的三种方式
iOS拨打电话的三种方式 1,这种方法,拨打完电话回不到原来的应用,会停留在通讯录里,而且是直接拨打,不弹出提示 1 2 var string = "tel:" + "1 ...
- iOS字体加载三种方式
静态加载 动态加载 动态下载苹果提供的多种字体 其他 打印出当前所有可用的字体 检查某字体是否已经下载 这是一篇很简短的文章,介绍了 iOS 自定义字体加载的三种方式. 静态加载 这个可以说是最简单最 ...
- iOS:延时执行的三种方式
延时执行的三种方式:performSelectorXXX方法.GCD中延时函数.创建定时器 第一种方式:NSObject分类当中的方法,延迟一段时间调用某一个方法 @interface NSObj ...
- 第三篇、image 设置圆角的几种方式
第一种: 就拿view来举例 view.layer.masksToBounds=YES; //设置为yes,就可以使用圆角 view.layer.cornerRadius= ; //设置它的圆角大小 ...
- iOS设置圆角的四种方法
小小圆角问题,正常情况下,我们不需要过多关心,但当屏幕内比较多的时候,还是有必要了解下性能问题的 一.设置CALayer的cornerRadius 这是最常用的,也是最简单的. cornerRadiu ...
- 为ScrollView增加圆角的三种方式,及自定义属性【在Linearlayout中新增ScrollView支持滚动 后续】
获取圆角的几种方案如下:方案一:通过shape来实现,给scrollView增加背景来实现方案二:通过自定义ScrollView,还要自定义属性,在dispatchDraw中不停的裁剪方案三:用And ...
- iOS逆传值的三种方式
1.代理 2.block 2.通知中心
- iOS开发 跳转场景的三种方式
iOS开发 跳转场景的三种方式 2012年10月17日, 15:32 假设A跳转到B,三种方法:1.按住ctrl键,拖动A上的控件(比如说UIButton)到B上,弹出菜单,选择Modal.不需要写任 ...
- 三种方式使得iOS应用能够在后台进行数据更新和下载
三种方式使得iOS程序即使在关闭或崩溃的情况下也能够在后台持续进行一些任务,比如更新程序界面快照,下载文件等.这三个方法分别是 Background Fetch,Remote Notification ...
随机推荐
- 二进制搭建kubernetes多master集群【一、使用TLS证书搭建etcd集群】
上一篇我们介绍了kubernetes集群架构以及系统参数配置,参考:二进制搭建kubernetes多master集群[开篇.集群环境和功能介绍] 下面本文etcd集群才用三台centos7.5搭建完成 ...
- 2018.09.28 hdu5435A serious math problem(数位dp)
传送门 数位dp卡常题. 写了一发dfs版本的发现过不了233. 于是赶紧转循环版本. 预处理出f数组. f[i][j]f[i][j]f[i][j]表示前i位数异或和为j的方案数. 然后每次直接数位d ...
- 2018.09.24 bzoj1816: [Cqoi2010]扑克牌(二分答案)
传送门 简单二分答案. 我们二分最终有k个牌堆. 这样joker被选择的张数≤min(k,m)\le min(k,m)≤min(k,m) 并且joker需要被选择的张数应该是∑i−1nmax(0,k− ...
- xampp虚拟主机的配置
ps:来源 https://blog.csdn.net/qq_17335153/article/details/52091869 一.修改httpd.conf 文件目录 xampp => ...
- Repository模式中,Update总是失败及其解析(转)
出处:http://www.cnblogs.com/scy251147/p/3688844.html 关于Entity Framework中的Attached报错的完美解决方案终极版 前发表过一篇文章 ...
- 第九章:叹词(L'interjection )
➊叹词的使用词类 .拟声词.如: Ah !啊!呀!哎! Hein !嗯!呣!哎! Paf !啪!叭! Pouf !扑通(重物坠地声) Euh ...
- String、StringBuffer与StringBuilder之间区别(转)
最近学习到StringBuffer,心中有好些疑问,搜索了一些关于String,StringBuffer,StringBuilder的东西,现在整理一下. 关于这三个类在字符串处理中的位置不言而喻,那 ...
- C程序之修改Windows的控制台大小
//change the console size #include <stdio.h> #include<stdlib.h> //必须有 int main(int argc, ...
- HDU 1087 Super Jumping! Jumping! Jumping! (DP+LIS)
题意:给定一个长度为n的序列,让你求一个和最大递增序列. 析:一看,是不是很像LIS啊,这基本就是一样的,只不过改一下而已,d(i)表示前i个数中,最大的和并且是递增的, 如果 d(j) + a[i] ...
- python编码(六)
1. 字符编码简介 1.1. ASCII ASCII(American Standard Code for Information Interchange),是一种单字节的编码.计算机世界里一开始只有 ...