直接用iphonex截图后是没有圆角和刘海的,就像下面这样。
其实加圆角和刘海也很简单
第一步:截屏
第二步:打开我这个软件,并选取图片库中的那张图
第三步:添加圆角,刘海
第四步:将做好的图片保存到相册
还需要下边这张刘海的图片
可以上代码了(目前原图是固定的,没有从图片库选取)
// // 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截图如何带"刘海"和圆角就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。
如对本文有疑问, 点击进行留言回复!!
APP调用微信小程序,能拉起小程序,但是onResp回调不会被调用问题
Codeforces Round #657 (Div. 2) B. Dubious Cyrpto(思维,数学)
网友评论