溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

詳談iPhoneX截圖如何帶

發(fā)布時間:2020-10-19 02:52:32 來源:腳本之家 閱讀:165 作者:_小呵呵 欄目:移動開發(fā)

直接用iPhoneX截圖后是沒有圓角和劉海的,就像下面這樣。

詳談iPhoneX截圖如何帶

其實加圓角和劉海也很簡單

第一步:截屏

第二步:打開我這個軟件,并選取圖片庫中的那張圖

第三步:添加圓角,劉海

第四步:將做好的圖片保存到相冊

還需要下邊這張劉海的圖片

詳談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);
}
//保存成功后回調(diào)
-(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截圖如何帶

以上這篇詳談iPhoneX截圖如何帶"劉海"和圓角就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持億速云。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI