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

首頁 > 系統 > iOS > 正文

iOS設置圓角的三種方法

2020-02-19 15:46:45
字體:
來源:轉載
供稿:網友

學習編程不是靠的死記硬背,也不是原班照套,當我們和大家分享了一些實例之后,我們的程序員要自己去開發其他功能,其實在IOS程序中也有很多隱藏的功能,以下是武林技術頻道小編給廣大網友們介紹的iOS設置圓角的三種方法,希望能幫到有需要的朋友。

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

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

#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設置圓角的三種方法,有需要的網友們可以認真看看,若是想獲得更多的專業訊息,可以繼續關注js.Vevb.com。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 汤原县| 镇雄县| 内丘县| 平定县| 泉州市| 桐梓县| 肇州县| 宁国市| 镶黄旗| 阳泉市| 积石山| 乌鲁木齐县| 凉山| 沙雅县| 东丽区| 大邑县| 咸阳市| 丹江口市| 尉氏县| 体育| 广宁县| 杭锦后旗| 会泽县| 锡林郭勒盟| 米泉市| 阿荣旗| 福鼎市| 阿瓦提县| 乌拉特后旗| 和静县| 公主岭市| 郸城县| 芦山县| 乐山市| 平舆县| 沁水县| 阳春市| 桑植县| 封丘县| 泰宁县| 千阳县|