Demo下载地址:http://download.csdn.net/download/u010981736/9950247
功能:iOS画板涂鸦,支持横竖屏适配,涂鸦的内容可以保存为图片,也可以把已有的图片添加到画板去修改,然后再保存为新的图片到相册。
效果图:
竖屏:
横屏:
核心代码:
界面使用XIB脱线完成的,做了横竖屏的适配;
ViewController文件
//
// HandleImageView.h
// 画板涂鸦
//
// Created by llkj on 2017/8/25.
// Copyright © 2017年 LayneCheung. All rights reserved.
//
#import <UIKit/UIKit.h>
@class HandleImageView;
@protocol HandleImageViewDelegate <NSObject>
- (void)handleImageView:(HandleImageView *)handleImageView newImage:(UIImage *)newImage;
@end
@interface HandleImageView : UIView
@property (nonatomic, weak) UIImage *image;
@property (nonatomic, weak) id<HandleImageViewDelegate> delegate;
@end
//
// ViewController.m
// 画板涂鸦
//
// Created by llkj on 2017/8/24.
// Copyright © 2017年 LayneCheung. All rights reserved.
//
#import "ViewController.h"
#import "DrawView.h"
#import "HandleImageView.h"
@interface ViewController ()<UINavigationControllerDelegate, UIImagePickerControllerDelegate, HandleImageViewDelegate>
@property (weak, nonatomic) IBOutlet DrawView *drawView;
@end
@implementation ViewController
//清屏
- (IBAction)clear:(id)sender {
[self.drawView clear];
}
// 撤销
- (IBAction)undo:(id)sender {
[self.drawView undo];
}
//橡皮擦
- (IBAction)eraser:(id)sender {
[self.drawView erase];
}
//设置线的宽度
- (IBAction)setLineWidth:(UISlider *)sender {
[self.drawView setLineWith:sender.value];
}
//设置线的颜色
- (IBAction)setLineColor:(UIButton *)sender {
[self.drawView setLineColor:sender.backgroundColor];
}
//照片
- (IBAction)photo:(id)sender {
// 从系统相册中选择图片
// 1.弹出相册
UIImagePickerController *vc = [[UIImagePickerController alloc] init];
// 设置照片来源
vc.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
vc.delegate = self;
// modal出来相册
[self