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

首頁 > 系統(tǒng) > iOS > 正文

iOS設置圓角的三種方法

2019-10-21 18:44:09
字體:
來源:轉載
供稿:網(wǎng)友

本文實例為大家分享了iOS設置圓角的三種方式,供大家參考,具體內容如下

第一種方法:通過設置layer的屬性

最簡單的一種,但是很影響性能,一般在正常的開發(fā)中使用很少.

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設置圓角

#import "ViewController.h"#import <AVFoundation/AVFoundation.h>@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 200, 100)];  imageView.image = [UIImage imageNamed:@"1"];  UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:imageView.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(25, 5)];  CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];  maskLayer.frame = imageView.bounds;  maskLayer.path = maskPath.CGPath;  imageView.layer.mask = maskLayer;  [self.view addSubview:imageView];}

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

效果圖:

iOS,圓角

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關教程知識閱讀請移步到IOS開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 通渭县| 怀化市| 明水县| 抚远县| 宜章县| 江永县| 连城县| 阜南县| 敖汉旗| 日土县| 浙江省| 喜德县| 石泉县| 敦化市| 灵川县| 星座| 吉木萨尔县| 铁岭县| 梅河口市| 吴桥县| 乐亭县| 永昌县| 封丘县| 清苑县| 雷波县| 巴青县| 五寨县| 汪清县| 错那县| 于田县| 忻州市| 沙湾县| 来安县| 永新县| 乌兰浩特市| 五莲县| 榆社县| 娄烦县| 县级市| 崇礼县| 兰西县|