iOS上生成圆角图片
来源:互联网 发布:linux 脚本 while 死 编辑:程序博客网 时间:2024/05/18 18:04
图片框圆角处理(UIImageView):
添加QuartzCore.framework
导入库头文件
#import “QuartzCore/QuartzCore.h”
//圆角设置
imageView.layer.cornerRadius = 8;(值越大,角就越圆)
imageView.layer.masksToBounds = YES;
//边框宽度及颜色设置
[imageView.layer setBorderWidth:2];
[imageView.layer setBorderColor:[UIColor blueColor]];
//设置边框为蓝色
//自动适应,保持图片宽高比
imageView.contentMode = UIViewContentModeScaleAspectFit;
还有一种方法 写成一个类
Phone上的程序在显示头像之类的图片时,基本上都是使用圆角的方式,比如TweetBot这个评价最高的Twitter客户端。stackoverflow上也有很多关于如何实现圆角图片的问题,实现方法有不少,不过最简单的实现是使用CALayer
CALayer *roundedLayer = [self layer];[roundedLayer setMasksToBounds:YES];roundedLayer.cornerRadius = 5.0;roundedLayer.borderColor = [[UIColor grayColor] CGColor];
其中的cell是因为图片在UITableView中使用。但是如果要在每次想要使用圆角图片的时候,都要写上这么写代码的话,就不符合码农懒的特性。既然iOS没有提供圆角的UIImageView,那么我们就自己来创建一个UIRoundedImageView。那么把这段代码加到哪里呢?这里,
(void)willMoveToWindow:(UIWindow *)newWindow{ CALayer *roundedLayer = [self layer]; [roundedLayer setMasksToBounds:YES]; roundedLayer.cornerRadius = 5.0; roundedLayer.borderColor = [[UIColor grayColor] CGColor];}
之后再把UIImageView控件的Custom Class设置为UIRoundedImageView
0 0
- iOS上生成圆角图片
- iOS上生成圆角图片
- iOS上生成圆角图片
- ios生成圆角图片
- iOS UIImage生成高性能圆角图片
- ios怎么让图片只有上半边圆角?
- ios 生成图片缩略图
- ios 生成图片缩略图
- iOS 生成条纹图片
- iOS生成二维码图片
- C# 在图片上生成图片水印
- ios 生成二维码图片libqrencode
- IOS 7+ 生成二维码图片
- iOS CoreImage 生成BitMap 图片
- iOS 生成二维码带图片
- iOS 截取view生成图片
- iOS 圆角图片
- iOS 图片圆角
- iOS 常用第三方库
- JAVA之编码---->CSV在文本下是正常的,用EXCEL打开是乱码的问题
- cocos2dx2.2移植到Android
- C#子窗体运行时无法正常最大化的解决办法
- ocos2d-x Win32下的节点缩放原理研究心得
- iOS上生成圆角图片
- OpenGL GLUT扩展库安装与配置(Windows Visual Studio2008)
- httpd.conf配置详解
- imagick-3.1.0RC2 安装错误
- Java输入与输出
- Working with Strings
- 技术网址收集
- cocos2dx在windows下开发,编译到android上(1)
- UTF-8 的BOM带来的麻烦