日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

IOS开发基础之画板案例软件的开发

發(fā)布時間:2023/12/18 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 IOS开发基础之画板案例软件的开发 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

IOS開發(fā)基礎(chǔ)之畫板案例軟件的開發(fā)

值此元宵佳節(jié),我依然在學(xué)習(xí)IOS,幾天沒有更新博客了。今天更新了一下。
源碼在我的主頁里面。
info.plist里面加入這樣的代碼,防止截圖的時候有問題

<key>NSPhotoLibraryAddUsageDescription</key> <string>save</string>

主要源代碼

// // LJView.h // 畫板 // // Created by 魯軍 on 2021/2/24. //#import <UIKit/UIKit.h>NS_ASSUME_NONNULL_BEGIN@interface LJView : UIView @property(nonatomic,assign)CGFloat lineWidth;@property(nonatomic,strong)UIColor *lineColor; - (void)clear;- (void)back;- (void)eraser; @endNS_ASSUME_NONNULL_END // // LJView.m // 畫板 // // Created by 魯軍 on 2021/2/24. //#import "LJView.h" #import "LJBezierPath.h"@interface LJView ()//@property(nonatomic,strong) LJBezierPath *path; @property(nonatomic,strong)NSMutableArray *paths ; @end@implementation LJView//- (LJBezierPath *)path{ // if(!_path){ // _path = [LJBezierPath bezierPath]; // } // return _path; //}- (NSMutableArray *)paths{if(!_paths){_paths= [NSMutableArray array];}return _paths; }- (void)clear{[self.paths removeAllObjects];[self setNeedsDisplay]; }- (void)back{[self.paths removeLastObject];[self setNeedsDisplay]; }//橡皮 - (void)eraser{self.lineColor = self.backgroundColor;} - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{LJBezierPath *path = [LJBezierPath bezierPath];//起點(diǎn)UITouch *t =touches.anyObject;CGPoint p = [t locationInView:t.view];// [self.path moveToPoint:p];[path moveToPoint:p];[path setLineWidth:self.lineWidth];[path setLineColor1:self.lineColor];[self.paths addObject:path];}- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{// LJBezierPath *path = [LJBezierPath bezierPath];//起點(diǎn)UITouch *t =touches.anyObject;CGPoint p = [t locationInView:t.view]; // [self.path addLineToPoint:p];[[self.paths lastObject] addLineToPoint:p];[self setNeedsDisplay];} - (void)drawRect:(CGRect)rect{// [self.path setLineWidth:self.lineWidth];// [self.path stroke];// 渲染for(LJBezierPath *path in self.paths ){[path setLineJoinStyle:kCGLineJoinRound];[path setLineCapStyle:kCGLineCapRound];// [self.lineColor set];[path.lineColor1 set];[path stroke];} }@end // // LJBezierPath.h // 畫板 // // Created by 魯軍 on 2021/2/26. //#import <UIKit/UIKit.h>NS_ASSUME_NONNULL_BEGIN@interface LJBezierPath : UIBezierPath@property(nonatomic,strong)UIColor *lineColor1;@endNS_ASSUME_NONNULL_END // // LJBezierPath.m // 畫板 // // Created by 魯軍 on 2021/2/26. //#import "LJBezierPath.h"@implementation LJBezierPath@end // // ViewController.m // 畫板 // // Created by 魯軍 on 2021/2/24. //#import "ViewController.h" #import "LJView.h"@interface ViewController () @property (weak, nonatomic) IBOutlet LJView *ljView; @property (weak, nonatomic) IBOutlet UISlider *lineWidthProgress; @property (weak, nonatomic) IBOutlet UIButton *firstBtn;@end@implementation ViewController- (IBAction)clear:(id)sender {[self.ljView clear]; }- (IBAction)back:(id)sender {[self.ljView back]; }- (IBAction)eraser:(id)sender {[self.ljView eraser]; }- (IBAction)save:(id)sender {//1開啟圖片類型的上下文UIGraphicsBeginImageContextWithOptions(self.ljView.bounds.size, NO, 0);//4 獲取當(dāng)前上下文CGContextRef ctx = UIGraphicsGetCurrentContext();//3 截圖[self.ljView.layer renderInContext:ctx];//5取圖片UIImage *image = UIGraphicsGetImageFromCurrentImageContext();//2.關(guān)閉上下文UIGraphicsEndImageContext();//6.保存圖片UIImageWriteToSavedPhotosAlbum(image, NULL, NULL, NULL);} - (IBAction)lineWidthChange:(UISlider *)sender {self.ljView.lineWidth = sender.value;} - (IBAction)lineColorChange:(UIButton *)sender {self.ljView.lineColor = sender.backgroundColor;}- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.self.ljView.lineWidth = self.lineWidthProgress.value;[self lineColorChange:self.firstBtn];}@end

總結(jié)

以上是生活随笔為你收集整理的IOS开发基础之画板案例软件的开发的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。