国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS設置圓角的三種方式

2019-10-21 18:48:04
字體:
來源:轉載
供稿:網友

第一種方法:通過設置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];

第二種方法:使用貝塞爾曲線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];

第三種方法:使用CAShapeLayer和UIBezierPath設置圓角

首先需要導入<AVFoundation/AVFoundation.h>

#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {  [super viewDidLoad];  UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];  imageView.image = [UIImage imageNamed:@"1"];  UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:imageView.bounds byRoundingCorners:UIRectCornerAllCorners 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];}

這三種方法中第三種最好,對內存的消耗最少啊,而且渲染快速。

以上所述是小編給大家介紹的iOS設置圓角的三種方式,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對VEVB武林網網站的支持!


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 弋阳县| 海盐县| 那曲县| 漠河县| 石河子市| 洞头县| 贵州省| 游戏| 姚安县| 蓬莱市| 井陉县| 绥宁县| 大连市| 汤阴县| 浮山县| 明光市| 锦州市| 穆棱市| 射洪县| 原平市| 志丹县| 江源县| 灯塔市| 公安县| 巢湖市| 上杭县| 平乐县| 信阳市| 汶川县| 图们市| 霸州市| 汝州市| 安泽县| 松潘县| 鄄城县| 河曲县| 西乌珠穆沁旗| 桦南县| 孙吴县| 潮州市| 赤水市|