直接用iphonex截圖后是沒有圓角和劉海的,就像下面這樣。
其實加圓角和劉海也很簡單
第一步:截屏
第二步:打開我這個軟件,并選取圖片庫中的那張圖
第三步:添加圓角,劉海
第四步:將做好的圖片保存到相冊
還需要下邊這張劉海的圖片
可以上代碼了(目前原圖是固定的,沒有從圖片庫選取)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
// // viewcontroller.m // iphonexphotoedit // // created by yfc on 2017/12/23. // copyright © 2017年 yfc. all rights reserved. // #import "viewcontroller.h" #import <assetslibrary/assetslibrary.h> #import <photos/photos.h> @interface viewcontroller () @end @implementation viewcontroller - ( void )viewdidload { [super viewdidload]; uibutton *btn = [[uibutton alloc]init]; btn.frame = cgrectmake(10, 44, 350, 758); btn.frame = cgrectmake(0, 0, 375, 812); [btn setbackgroundimage:[uiimage imagenamed:@ "img_3655.png" ] forstate:uicontrolstatenormal]; //添加圓角 btn.layer.cornerradius = 35 ; btn.layer.bordercolor = [uicolor blackcolor].cgcolor; btn.layer.borderwidth = 2; [self.view addsubview:btn]; btn.backgroundcolor = [uicolor whitecolor]; btn.clipstobounds = yes; //添加劉海 uiimageview *imageview = [[uiimageview alloc]initwithimage:[uiimage imagenamed:@ "liuhai.png" ]]; imageview.frame = cgrectmake(70, 0, 222, 28); [btn addsubview:imageview]; self.view.backgroundcolor = [uicolor clearcolor]; //截圖保存到相冊 dispatch_after(dispatch_time(dispatch_time_now, (int64_t)(1 * nsec_per_sec)), dispatch_get_main_queue(), ^{ [self savebtnaction:nil]; }); } -( void )savebtnaction:(uibutton *)sender{ [self requestauthorizationstatus]; } //查看權限 - ( void )requestauthorizationstatus { [phphotolibrary requestauthorization:^(phauthorizationstatus status){ dispatch_async(dispatch_get_main_queue(), ^{ switch (status) { case phauthorizationstatusauthorized: { [self cutscreen]; break ; } default : //denied { break ; } } }); }]; } //截屏 -( void )cutscreen{ uigraphicsbeginimagecontextwithoptions(self.view.bounds.size, yes, 0.0); //2.獲取當前圖形上下文 cgcontextref ctx = uigraphicsgetcurrentcontext(); //3.獲取需要截取的view的layer [self.view.layer renderincontext:ctx]; //4.從當前上下文獲取圖片 uiimage *image = uigraphicsgetimagefromcurrentimagecontext(); //5.關閉圖形上下文 uigraphicsendimagecontext(); //6.把圖片保存到相冊 uiimagewritetosavedphotosalbum(image, self, @selector(image:didfinishsavingwitherror:contextinfo:), null); } //保存成功后回調 -( void )image:(uiimage *)image didfinishsavingwitherror:(nserror *)error contextinfo:( void *)contextinfo{ nsstring *msg = nil; if (error) { msg = @ "圖片保存失敗" ; } else { msg = @ "圖片保存成功" ; } uialertview *alertview = [[uialertview alloc] initwithtitle:@ "提示" message:msg delegate:self cancelbuttontitle:@ "確定" otherbuttontitles:nil, nil]; [alertview show]; } @end |
效果圖是
以上這篇詳談iphonex截圖如何帶"劉海"和圓角就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持服務器之家。
原文鏈接:http://blog.csdn.net/qq_15509071/article/details/78879426