UIImageView 的圆角效果
2015-08-14 14:49
423 查看
iOS 中给图片加圆角的最好方法是什么?
加圆角有很多方法,比如:在CALayer中设置cornerRadius属性, 但是很慢, 尤其是图片作为头像显示在UITableView中.
用一张头像的placeholder的图, 但是要多读取一张图.
直接将图片裁剪并加上透明圆角. 但是每张图都要处理.
我认为最好的方法是
4. drawRect中使用UIBezierPath画一个圆角的path, 然后clip. 但是如果把UIView的opaque设置成YES, 就会出现黑色的边. 不知道有什么办法可以避免这个问题又能得到最高性能.
第一是直接设置参数:
view.layer.shouldRasterize = YES;
view.layer.rasterizationScale = view.window.screen.scale; // or [UIScreen mainScreen] 原文链接:http://stackoverflow.com/questions/11049016/cliptobounds-and-maskstobounds-performance-issue 第二是你说的UIBezierPath的方法,我觉得也挺好的呀: // Get your image somehow UIImage *image = [UIImage imageNamed:@"image.jpg"]; // Begin a new image that will be the new image with the rounded corners // (here with the size of an UIImageView) UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 1.0); // Add a clip before drawing anything, in the shape of an rounded rect [[UIBezierPath bezierPathWithRoundedRect:imageView.bounds cornerRadius:10.0] addClip]; // Draw your image [image drawInRect:imageView.bounds]; // Get the image, here setting the UIImageView image imageView.image = UIGraphicsGetImageFromCurrentImageContext(); // Lets forget about that we were drawing UIGraphicsEndImageContext(); 原文链接:http://stackoverflow.com/questions/17593524/using-cornerradius-on-a-uiimageview-in-a-uitableviewcell
相关文章推荐
- GPUImage说明 各文件说明
- UITextField用法大全
- iOS开发 -- UITextField
- iOS UILabel设置居上对齐,居中对齐,居下对齐
- MOS文章实验:ORA-01722 from Queries with Dependent Predicates
- [自我记录贴] IntelliJ & Android Studio Issues
- uva 11572 Unique Snowflakes
- 128. Longest Consecutive Sequence
- NameValueCollection详解
- iOS8 中 UIVisualEffectView 模糊效果的使用
- Android Volley彻底解决(三),定制自己Request
- Interview questions
- Git Gui for Windows的建库、克隆(clone)、上传(push)、下载(pull)、合并
- 在多线程中进行UI操作
- UIAlertView study
- UITableView的section设置了headerView导致下滑的时候headerView跟着滚动的解决方法
- 在hibernate+mysql:Field 'id' doesn't have a default value
- 《深入理解Android 卷III》第七章 深入理解SystemUI
- 【UISwitch开关控件】
- Codeforces 570 D. Tree Requests