Parcourir la source

PDFViewer(ios) - ui交互功能的基本实现(选择图片未实现)

dengkang il y a 2 ans
Parent
commit
1d20203886

+ 1 - 9
PDFViewer.xcodeproj/project.pbxproj

@@ -21,7 +21,6 @@
 		EC6297BD292239C200D339EE /* CPDFListController.m in Sources */ = {isa = PBXBuildFile; fileRef = EC6297BC292239C200D339EE /* CPDFListController.m */; };
 		ECC8831D2923352B00F6392E /* CPDFViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = ECC8831C2923352B00F6392E /* CPDFViewController.m */; };
 		ECD0ABF02928ED9A0091B6EB /* CPDFTextPreview.m in Sources */ = {isa = PBXBuildFile; fileRef = ECD0ABE52928ED990091B6EB /* CPDFTextPreview.m */; };
-		ECD0ABF12928ED9A0091B6EB /* CPDFPageRangeDropDownList.m in Sources */ = {isa = PBXBuildFile; fileRef = ECD0ABE62928ED990091B6EB /* CPDFPageRangeDropDownList.m */; };
 		ECD0ABF32928ED9A0091B6EB /* CPDFImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = ECD0ABE82928ED990091B6EB /* CPDFImageView.m */; };
 		ECD0ABF42928ED9A0091B6EB /* CPDFTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = ECD0ABEA2928ED990091B6EB /* CPDFTextView.m */; };
 		ECD0ABF52928ED9A0091B6EB /* CPDFImagePreview.m in Sources */ = {isa = PBXBuildFile; fileRef = ECD0ABEC2928ED9A0091B6EB /* CPDFImagePreview.m */; };
@@ -77,14 +76,12 @@
 		ECC8831B2923352B00F6392E /* CPDFViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CPDFViewController.h; sourceTree = "<group>"; };
 		ECC8831C2923352B00F6392E /* CPDFViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CPDFViewController.m; sourceTree = "<group>"; };
 		ECD0ABE52928ED990091B6EB /* CPDFTextPreview.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CPDFTextPreview.m; sourceTree = "<group>"; };
-		ECD0ABE62928ED990091B6EB /* CPDFPageRangeDropDownList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CPDFPageRangeDropDownList.m; sourceTree = "<group>"; };
 		ECD0ABE82928ED990091B6EB /* CPDFImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CPDFImageView.m; sourceTree = "<group>"; };
 		ECD0ABE92928ED990091B6EB /* CPDFTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPDFTextView.h; sourceTree = "<group>"; };
 		ECD0ABEA2928ED990091B6EB /* CPDFTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CPDFTextView.m; sourceTree = "<group>"; };
 		ECD0ABEB2928ED9A0091B6EB /* CPDFImagePreview.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPDFImagePreview.h; sourceTree = "<group>"; };
 		ECD0ABEC2928ED9A0091B6EB /* CPDFImagePreview.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CPDFImagePreview.m; sourceTree = "<group>"; };
 		ECD0ABED2928ED9A0091B6EB /* CPDFImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPDFImageView.h; sourceTree = "<group>"; };
-		ECD0ABEE2928ED9A0091B6EB /* CPDFPageRangeDropDownList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPDFPageRangeDropDownList.h; sourceTree = "<group>"; };
 		ECD0ABEF2928ED9A0091B6EB /* CPDFTextPreview.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPDFTextPreview.h; sourceTree = "<group>"; };
 		ECD0ABF92928EECA0091B6EB /* NSArray+MASAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+MASAdditions.h"; sourceTree = "<group>"; };
 		ECD0ABFA2928EECA0091B6EB /* View+MASAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "View+MASAdditions.h"; sourceTree = "<group>"; };
@@ -118,7 +115,6 @@
 		ECD0AC252928F2E50091B6EB /* CPDFImageViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CPDFImageViewController.m; sourceTree = "<group>"; };
 		ECD0AC30292B56C90091B6EB /* CPDFDataModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CPDFDataModel.h; sourceTree = "<group>"; };
 		ECD0AC31292B56C90091B6EB /* CPDFDataModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CPDFDataModel.m; sourceTree = "<group>"; };
-		ECE319732924849C00DB9D2F /* pdfImage@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "pdfImage@2x.png"; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -165,8 +161,8 @@
 				EC6297B52922393F00D339EE /* Controller */,
 				EC6297AD29222D3100D339EE /* Model */,
 				ECD0ABE42928ED5D0091B6EB /* View */,
-				EC62978C29220F8300D339EE /* AppDelegate.h */,
 				EC62978D29220F8300D339EE /* AppDelegate.m */,
+				EC62978C29220F8300D339EE /* AppDelegate.h */,
 				EC62978F29220F8300D339EE /* SceneDelegate.h */,
 				EC62979029220F8300D339EE /* SceneDelegate.m */,
 				EC62979229220F8300D339EE /* ViewController.h */,
@@ -215,8 +211,6 @@
 				ECD0ABEC2928ED9A0091B6EB /* CPDFImagePreview.m */,
 				ECD0ABED2928ED9A0091B6EB /* CPDFImageView.h */,
 				ECD0ABE82928ED990091B6EB /* CPDFImageView.m */,
-				ECD0ABEE2928ED9A0091B6EB /* CPDFPageRangeDropDownList.h */,
-				ECD0ABE62928ED990091B6EB /* CPDFPageRangeDropDownList.m */,
 				ECD0ABEF2928ED9A0091B6EB /* CPDFTextPreview.h */,
 				ECD0ABE52928ED990091B6EB /* CPDFTextPreview.m */,
 				ECD0ABE92928ED990091B6EB /* CPDFTextView.h */,
@@ -260,7 +254,6 @@
 		ECD0AC1E2928EF030091B6EB /* sources */ = {
 			isa = PBXGroup;
 			children = (
-				ECE319732924849C00DB9D2F /* pdfImage@2x.png */,
 				ECD0AC1F2928EF260091B6EB /* btn_selected.png */,
 			);
 			path = sources;
@@ -355,7 +348,6 @@
 				ECD0AC132928EECB0091B6EB /* MASConstraintMaker.m in Sources */,
 				ECD0AC1A2928EECB0091B6EB /* ViewController+MASAdditions.m in Sources */,
 				ECD0AC142928EECB0091B6EB /* NSLayoutConstraint+MASDebugAdditions.m in Sources */,
-				ECD0ABF12928ED9A0091B6EB /* CPDFPageRangeDropDownList.m in Sources */,
 				ECD0AC162928EECB0091B6EB /* NSArray+MASAdditions.m in Sources */,
 				ECD0AC192928EECB0091B6EB /* MASViewConstraint.m in Sources */,
 				EC62979129220F8300D339EE /* SceneDelegate.m in Sources */,

+ 8 - 0
PDFViewer.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>PreviewsEnabled</key>
+	<false/>
+</dict>
+</plist>

BIN
PDFViewer.xcodeproj/project.xcworkspace/xcuserdata/kdan.xcuserdatad/UserInterfaceState.xcuserstate


+ 18 - 0
PDFViewer.xcodeproj/project.xcworkspace/xcuserdata/kdan.xcuserdatad/WorkspaceSettings.xcsettings

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>BuildLocationStyle</key>
+	<string>UseAppPreferences</string>
+	<key>CustomBuildLocationType</key>
+	<string>RelativeToDerivedData</string>
+	<key>DerivedDataLocationStyle</key>
+	<string>Default</string>
+	<key>IssueFilterStyle</key>
+	<string>ShowActiveSchemeOnly</string>
+	<key>LiveSourceIssuesEnabled</key>
+	<true/>
+	<key>ShowSharedSchemesAutomaticallyEnabled</key>
+	<true/>
+</dict>
+</plist>

+ 6 - 0
PDFViewer/Controller/CPDFImageViewController.h

@@ -10,6 +10,7 @@
 
 @class CPDFImagePreview;
 @class CPDFImageView;
+@class CPDFDataModel;
 
 NS_ASSUME_NONNULL_BEGIN
 
@@ -17,8 +18,13 @@ NS_ASSUME_NONNULL_BEGIN
 
 @property (nonatomic,strong) CPDFImagePreview *imagePreview;
 @property (nonatomic,strong) CPDFImageView *imageView;
+@property (nonatomic,strong) CPDFDataModel *dataModel;
 
+- (void)initDataModel;
 - (void)addTargets;
+- (void)addConstraint;
+- (void)createGestureRecognizer;
+- (void)createCustomRangeAlert;
 
 @end
 

+ 187 - 5
PDFViewer/Controller/CPDFImageViewController.m

@@ -8,10 +8,13 @@
 #import "CPDFImageViewController.h"
 #import "CPDFImageView.h"
 #import "CPDFImagePreview.h"
+#import "CPDFDataModel.h"
 #import "Masonry.h"
 
 @interface CPDFImageViewController ()
 
+@property (nonatomic,assign) CGRect watermarkFrame;
+
 @end
 
 @implementation CPDFImageViewController
@@ -21,23 +24,202 @@
     // Do any additional setup after loading the view.
     _imagePreview = [[CPDFImagePreview alloc] init];
     _imageView = [[CPDFImageView alloc] init];
-
+    _dataModel = [[CPDFDataModel alloc] init];
+    
     [self.view addSubview:_imagePreview];
     [self.view addSubview:_imageView];
+    [self.view setBackgroundColor:UIColor.systemGray5Color];
+    
+    [self initDataModel];
+    [self addConstraint];
+    [self addTargets];
+    [self createGestureRecognizer];
+
+}
+
+- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
+    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
     
-    UIEdgeInsets previewPadding = UIEdgeInsetsMake(0, 0, self.view.bounds.size.height / 3, 0);
+    if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) {
+        
+        [_imageView mas_remakeConstraints:^(MASConstraintMaker *make) {
+            make.right.equalTo(self.view.mas_right).offset(-30);
+            make.left.equalTo(_imagePreview.mas_right).offset(0);
+            make.height.equalTo(@205);
+            make.width.equalTo(@(self.view.bounds.size.width));
+            make.bottom.equalTo(self.view.mas_bottom).offset(-55);
+        }];
+        [_imagePreview mas_remakeConstraints:^(MASConstraintMaker *make) {
+            make.top.equalTo(self.view.mas_top).offset(10);
+            make.right.equalTo(_imageView.mas_left).offset(-5);
+            make.left.equalTo(self.view.mas_left).offset(0);
+            make.bottom.equalTo(self.view.mas_bottom).offset(0);
+        }];
+        
+    } else if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) {
+        [_imagePreview mas_remakeConstraints:^(MASConstraintMaker *make) {
+            make.top.equalTo(self.view.mas_top).offset(0);
+            make.width.equalTo(self.view.mas_width);
+            make.bottom.equalTo(self.view.mas_bottom).offset(-205);
+        }];
+
+        [_imageView mas_remakeConstraints:^(MASConstraintMaker *make) {
+            make.top.equalTo(_imagePreview.mas_bottom).offset(0);
+            make.width.equalTo(_imagePreview.mas_width);
+            make.bottom.equalTo(self.view.mas_bottom).offset(0);
+        }];
+    }
+}
+
+- (void)initDataModel {
+    _dataModel.watermarkOpacity = 1;
+    _dataModel.imagePath = @"btn_selected";
+    _dataModel.watermarkScale = 1;
+    _dataModel.isTile = NO;
+    _dataModel.watermarkRotation = 0;
+    _imageView.horizontalField.text = 0;
+    _imageView.verticalField.text = 0;
+    _imageView.horizontalField.enabled = NO;
+    _imageView.verticalField.enabled = NO;
+    _imageView.imageScaleSlider.enabled = YES;
+    _imagePreview.watermarkView.image = [UIImage imageNamed:_dataModel.imagePath];
+}
+
+- (void)addConstraint {
     [_imagePreview mas_makeConstraints:^(MASConstraintMaker *make) {
-        make.edges.equalTo(self.view).with.insets(previewPadding);
+        make.top.equalTo(self.view.mas_top).offset(0);
+        make.width.equalTo(self.view.mas_width);
+        make.bottom.equalTo(self.view.mas_bottom).offset(-205);
     }];
 
-    UIEdgeInsets imageViewPadding = UIEdgeInsetsMake(430, 0, 0, 0);
     [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
-        make.edges.equalTo(self.view).with.insets(imageViewPadding);
+        make.top.equalTo(_imagePreview.mas_bottom).offset(0);
+        make.width.equalTo(_imagePreview.mas_width);
+        make.bottom.equalTo(self.view.mas_bottom).offset(0);
     }];
 }
 
 - (void)addTargets {
+    [_imageView.selectBtn addTarget:self action:@selector(onSelectBtnClicked:) forControlEvents:UIControlEventTouchDown];
+    [_imageView.opacitySlider addTarget:self action:@selector(onOpacityChanged:) forControlEvents:UIControlEventValueChanged];
+    [_imageView.imageScaleSlider addTarget:self action:@selector(onImageScaleChanged:) forControlEvents:UIControlEventValueChanged];
+    [_imageView.tileSwitch addTarget:self action:@selector(onTileSwitchChanged:) forControlEvents:UIControlEventValueChanged];
+    [_imageView.pageBtn addTarget:self action:@selector(onSelectPageRange:) forControlEvents:UIControlEventTouchDown];
+}
+
+- (void)createGestureRecognizer {
+    [_imagePreview.documentView setUserInteractionEnabled:YES];
+    [_imagePreview.watermarkView setMultipleTouchEnabled:YES];
+    [_imagePreview.watermarkView setUserInteractionEnabled:YES];
+    [_imagePreview.rotationBtn setUserInteractionEnabled:YES];
+    
+    UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panWatermarkView:)];
+    [_imagePreview.watermarkView addGestureRecognizer:panRecognizer];
+    
+    UIPanGestureRecognizer *panRotationBtnRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(rotateWatermarkView:)];
+    [_imagePreview.rotationBtn addGestureRecognizer:panRotationBtnRecognizer];
+}
+
+- (void)rotateWatermarkView:(UIPanGestureRecognizer *)recognizer {
+    CGPoint point = [recognizer translationInView:_imagePreview];
+    CGFloat radian = atan2(point.x + _imagePreview.center.x - _imagePreview.watermarkView.center.x,point.y + _imagePreview.center.y - _imagePreview.watermarkView.center.y);
+    _imagePreview.watermarkView.transform = CGAffineTransformMakeRotation(-radian);
+    _dataModel.watermarkRotation = (-radian) * 180 / M_PI;
+}
+
+- (void)panWatermarkView:(UIPanGestureRecognizer *)recognizer {
+    CGPoint point = [recognizer translationInView:_imagePreview.documentView];
+    CGRect documentFrame = _imagePreview.documentView.frame;
+    documentFrame.origin.x -= _imagePreview.documentView.frame.origin.x;
+    documentFrame.origin.y -= _imagePreview.documentView.frame.origin.y;
     
+    [_imagePreview.watermarkView setCenter:CGPointMake(_imagePreview.watermarkView.center.x + point.x, _imagePreview.watermarkView.center.y + point.y)];
+    [_imagePreview.rotationBtn setCenter:CGPointMake(_imagePreview.rotationBtn.center.x + point.x, _imagePreview.rotationBtn.center.y + point.y)];
+    
+    if (!CGRectContainsRect(documentFrame,_imagePreview.watermarkView.frame)) {
+        [_imagePreview.watermarkView setCenter:CGPointMake(_imagePreview.watermarkView.center.x - point.x, _imagePreview.watermarkView.center.y - point.y)];
+        [_imagePreview.rotationBtn setCenter:CGPointMake(_imagePreview.rotationBtn.center.x - point.x, _imagePreview.rotationBtn.center.y - point.y)];
+    }
+    
+    _dataModel.tx = _imagePreview.watermarkView.frame.origin.x - (_imagePreview.documentView.center.x - _imagePreview.documentView.frame.origin.x);
+    _dataModel.ty = _imagePreview.documentView.center.y - _imagePreview.documentView.frame.origin.y - _imagePreview.watermarkView.frame.origin.y;
+    [recognizer setTranslation:CGPointZero inView:_imagePreview.documentView];
+}
+
+- (void)onSelectBtnClicked:(UIButton *)sender {
+    
+}
+
+- (void)onOpacityChanged:(UISlider *)sender {
+    _imagePreview.watermarkView.alpha =  1 - sender.value;
+    [_dataModel setWatermarkOpacity:1 - sender.value];
+}
+
+- (void)onImageScaleChanged:(UISlider *)sender {
+    sender.minimumValue = 1;
+    sender.maximumValue = 3;
+    
+    _watermarkFrame.size.width = sender.value * [UIImage imageNamed:_dataModel.imagePath].size.width;
+    _watermarkFrame.size.height = sender.value * [UIImage imageNamed:_dataModel.imagePath].size.height;;
+    _watermarkFrame.origin.x = _imagePreview.watermarkView.frame.origin.x;
+    _watermarkFrame.origin.y = _imagePreview.watermarkView.frame.origin.y;
+    _imagePreview.watermarkView.frame = _watermarkFrame;
+    _imagePreview.watermarkFrame = _watermarkFrame;
+    
+    [_imagePreview.rotationBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
+        make.top.equalTo(_imagePreview.watermarkView.mas_bottom).offset(-10);
+        make.width.equalTo(@20);
+        make.height.equalTo(@20);
+        make.left.equalTo(_imagePreview.watermarkView.mas_right).offset(-10);
+    }];
+    [_dataModel setWatermarkScale:sender.value];
+}
+
+- (void)onSelectPageRange:(UIButton *)sender {
+    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
+    UIAlertAction *defaultRange = [UIAlertAction actionWithTitle:@"All Pages" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+        self.imageView.rangeLabel.text = @"Page Range: ALL";
+        }];
+    UIAlertAction *customRange = [UIAlertAction actionWithTitle:@"Custom Page Range" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+        [self createCustomRangeAlert];
+        }];
+    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
+            
+        }];
+    [alertController addAction:defaultRange];
+    [alertController addAction:customRange];
+    [alertController addAction:cancelAction];
+    [self presentViewController:alertController animated:YES completion:nil];
+}
+
+- (void)createCustomRangeAlert {
+    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Custom Page Range" message:nil preferredStyle:UIAlertControllerStyleAlert];
+    
+    [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
+        textField.placeholder = @"such as:1,3-5,10";
+    }];
+    [alertController addAction:[UIAlertAction actionWithTitle:@"Done" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+        
+        self.dataModel.pageString = alertController.textFields.firstObject.text;
+        self.imageView.rangeLabel.text = @"Page Range:Custom";
+    }]];
+    [alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+    }]];
+    [self presentViewController:alertController animated:YES completion:nil];
+}
+
+- (void)onTileSwitchChanged:(UISwitch *) sender {
+    if ([sender isOn]) {
+        _dataModel.isTile = YES;
+        _imageView.horizontalField.enabled = YES;
+        _imageView.verticalField.enabled = YES;
+        _imageView.imageScaleSlider.enabled = NO;
+    } else {
+        _dataModel.isTile = NO;
+        _imageView.horizontalField.enabled = NO;
+        _imageView.verticalField.enabled = NO;
+        _imageView.imageScaleSlider.enabled = YES;
+    }
 }
 
 @end

+ 5 - 3
PDFViewer/Controller/CPDFListController.m

@@ -10,6 +10,9 @@
 #import "CPDFModel.h"
 #import "CPDFViewController.h"
 
+extern BOOL gImagePreviewIsFirstLayout;
+extern BOOL gTextPreviewIsFirstLayout;
+
 @interface CPDFListController () <UITableViewDataSource,UITableViewDelegate>
 
 @property (nonatomic,strong) UITableView *tableView;
@@ -114,10 +117,9 @@
     } else {
         
         CPDFViewController *pdfViewcontroller = [[CPDFViewController alloc] initWithPath:[self.dataArray[indexPath.row] filePath]];
-//        UIPageControl *pageControl = [[UIPageControl alloc] init];
-//        pdfViewcontroller.navigationItem.rightBarButtonItem ;
         [self.navigationController pushViewController:pdfViewcontroller animated:YES];
-        
+        gImagePreviewIsFirstLayout = YES;
+        gTextPreviewIsFirstLayout = YES;
     }
 }
 

+ 6 - 0
PDFViewer/Controller/CPDFTextViewController.h

@@ -19,8 +19,14 @@ NS_ASSUME_NONNULL_BEGIN
 @property (nonatomic,strong) CPDFTextPreview *textPreview;
 @property (nonatomic,strong) CPDFTextView *textView;
 @property (nonatomic,strong) CPDFDataModel *dataModel;
+@property (nonatomic,strong) UIAlertController *alertController;
 
+- (void)initDataModel;
 - (void)addTargets;
+- (void)addConstraint;
+- (void)watermarkAdaption;
+- (void)createGestureRecognizer;
+- (void)createCustomRangeAlert;
 
 @end
 

+ 190 - 19
PDFViewer/Controller/CPDFTextViewController.m

@@ -13,6 +13,8 @@
 
 @interface CPDFTextViewController ()
 
+@property (nonatomic,assign) CGRect watermarkFrame;
+
 @end
 
 @implementation CPDFTextViewController
@@ -24,20 +26,79 @@
     _textPreview = [[CPDFTextPreview alloc] init];
     _textView = [[CPDFTextView alloc] init];
     _dataModel = [[CPDFDataModel alloc] init];
+    _alertController = [UIAlertController alertControllerWithTitle:@"Watermark Content" message:nil preferredStyle:UIAlertControllerStyleAlert];
     
     [self.view addSubview:_textPreview];
     [self.view addSubview:_textView];
+    [self.view setBackgroundColor:UIColor.systemGray5Color];
     
-    UIEdgeInsets previewPadding = UIEdgeInsetsMake(0, 0, self.view.bounds.size.height / 3, 0);
-    [_textPreview mas_makeConstraints:^(MASConstraintMaker *make) {
-        make.edges.equalTo(self.view).with.insets(previewPadding);
-    }];
-
-    UIEdgeInsets textViewPadding = UIEdgeInsetsMake(430, 0, 0, 0);
-    [_textView mas_makeConstraints:^(MASConstraintMaker *make) {
-        make.edges.equalTo(self.view).with.insets(textViewPadding);
-    }];
+    [self addConstraint];
+    [self initDataModel];
     [self addTargets];
+    [self createGestureRecognizer];
+}
+
+
+- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
+    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
+    
+    if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) {
+        
+        [_textView mas_remakeConstraints:^(MASConstraintMaker *make) {
+            make.right.equalTo(self.view.mas_right).offset(-30);
+            make.left.equalTo(_textPreview.mas_right).offset(0);
+            make.height.equalTo(@205);
+            make.width.equalTo(@(self.view.bounds.size.width));
+            make.bottom.equalTo(self.view.mas_bottom).offset(-55);
+        }];
+        [_textPreview mas_remakeConstraints:^(MASConstraintMaker *make) {
+            make.top.equalTo(self.view.mas_top).offset(10);
+            make.right.equalTo(_textView.mas_left).offset(-5);
+            make.left.equalTo(self.view.mas_left).offset(0);
+            make.bottom.equalTo(self.view.mas_bottom).offset(0);
+        }];
+        
+    } else if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) {
+        [_textPreview mas_remakeConstraints:^(MASConstraintMaker *make) {
+            make.top.equalTo(self.view.mas_top).offset(0);
+            make.width.equalTo(self.view.mas_width);
+            make.bottom.equalTo(self.view.mas_bottom).offset(-205);
+        }];
+
+        [_textView mas_remakeConstraints:^(MASConstraintMaker *make) {
+            make.top.equalTo(_textPreview.mas_bottom).offset(0);
+            make.width.equalTo(_textPreview.mas_width);
+            make.bottom.equalTo(self.view.mas_bottom).offset(0);
+        }];
+    }
+}
+
+- (void)initDataModel {
+    _dataModel.textColor = UIColor.blackColor;
+    _dataModel.watermarkOpacity = 1;
+    _dataModel.text = @"Watermark";
+    _dataModel.watermarkScale = 1;
+    _dataModel.isTile = NO;
+    _dataModel.watermarkRotation = 0;
+    _textPreview.watermarkLabel.text = _dataModel.text;
+    _textView.horizontalField.text = 0;
+    _textView.verticalField.text = 0;
+    _textView.horizontalField.enabled = NO;
+    _textView.verticalField.enabled = NO;
+}
+
+- (void)addConstraint {
+        [_textPreview mas_makeConstraints:^(MASConstraintMaker *make) {
+            make.top.equalTo(self.view.mas_top).offset(0);
+            make.width.equalTo(self.view.mas_width);
+            make.bottom.equalTo(self.view.mas_bottom).offset(-205);
+        }];
+
+        [_textView mas_makeConstraints:^(MASConstraintMaker *make) {
+            make.top.equalTo(_textPreview.mas_bottom).offset(0);
+            make.width.equalTo(_textPreview.mas_width);
+            make.bottom.equalTo(self.view.mas_bottom).offset(0);
+        }];
 }
 
 - (void)addTargets {
@@ -46,9 +107,40 @@
         [_textView.colorArray[i] addTarget:self action:@selector(onColorBtnClicked:) forControlEvents:UIControlEventTouchDown];
     }
     
+    __block CPDFTextViewController *strongBlock = self;
+    [_alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
+        
+    }];
+    [_alertController addAction:[UIAlertAction actionWithTitle:@"Done" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+        
+        strongBlock.dataModel.text = strongBlock.alertController.textFields.firstObject.text;
+        strongBlock.textPreview.watermarkLabel.text = strongBlock.alertController.textFields.firstObject.text;
+        [strongBlock watermarkAdaption];
+        
+    }]];
+    [_alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+        strongBlock.alertController.view.hidden = YES;
+    }]];
+    
     [_textView.opacitySlider addTarget:self action:@selector(onOpacityChanged:) forControlEvents:UIControlEventValueChanged];
     [_textView.textScaleSlider addTarget:self action:@selector(onTextScaleChanged:) forControlEvents:UIControlEventValueChanged];
     [_textView.tileSwitch addTarget:self action:@selector(onTileSwitchChanged:) forControlEvents:UIControlEventValueChanged];
+    [_textView.pageBtn addTarget:self action:@selector(onSelectPageRange:) forControlEvents:UIControlEventTouchDown];
+}
+
+- (void)createGestureRecognizer {
+    [_textPreview.documentView setUserInteractionEnabled:YES];
+    [_textPreview.watermarkLabel setUserInteractionEnabled:YES];
+    [_textPreview.rotationBtn setUserInteractionEnabled:YES];
+      
+    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapWatermarkLabel:)];
+    [_textPreview.watermarkLabel addGestureRecognizer:tapGestureRecognizer];
+    
+    UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panWatermarkLabel:)];
+    [_textPreview.watermarkLabel addGestureRecognizer:panRecognizer];
+    
+    UIPanGestureRecognizer *panRotationBtnRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(rotationWatermarkLabel:)];
+    [_textPreview.rotationBtn addGestureRecognizer:panRotationBtnRecognizer];
 }
 
 - (void)onColorBtnClicked:(UIButton *)sender {
@@ -62,24 +154,103 @@
 }
 
 - (void)onTextScaleChanged:(UISlider *)sender {
-    sender.minimumValue = 24;
-    sender.maximumValue = 70;
-    _textPreview.watermarkLabel.font = [_textPreview.watermarkLabel.font fontWithSize:sender.value];
-    [_textPreview.watermarkLabel sizeToFit];
-    CGRect frame = _textPreview.watermarkLabel.frame;
-    frame.origin = CGPointMake(_textPreview.bounds.size.width / 2 - _textPreview.watermarkLabel.frame.size.width / 2, _textPreview.bounds.size.height / 2 - _textPreview.watermarkLabel.frame.size.height / 2);
-    _textPreview.watermarkLabel.frame = frame;
-    
-    _textPreview.rotationBtn.frame = CGRectMake(_textPreview.bounds.size.width / 2 + _textPreview.watermarkLabel.frame.size.width / 2 - 10, _textPreview.bounds.size.height / 2 + _textPreview.watermarkLabel.frame.size.height / 2 - 10, 20, 20);
-    [_dataModel setWatermarkScale:sender.value / 24];
+    if (!_dataModel.isTile) {
+        sender.minimumValue = 24;
+        sender.maximumValue = 48;
+        _textPreview.watermarkLabel.font = [_textPreview.watermarkLabel.font fontWithSize:sender.value];
+        [self watermarkAdaption];
+        [_dataModel setWatermarkScale:sender.value / 24];
+    }
 }
 
 - (void)onTileSwitchChanged:(UISwitch *) sender {
     if ([sender isOn]) {
         _dataModel.isTile = YES;
+        _textView.horizontalField.enabled = YES;
+        _textView.verticalField.enabled = YES;
+        _textView.textScaleSlider.enabled = NO;
     } else {
         _dataModel.isTile = NO;
+        _textView.horizontalField.enabled = NO;
+        _textView.verticalField.enabled = NO;
+        _textView.textScaleSlider.enabled = YES;
+    }
+}
+
+- (void)onSelectPageRange:(UIButton *)sender {
+    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
+    UIAlertAction *defaultRange = [UIAlertAction actionWithTitle:@"All Pages" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+        self.textView.rangeLabel.text = @"Page Range: ALL";
+        }];
+    UIAlertAction *customRange = [UIAlertAction actionWithTitle:@"Custom Page Range" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+        [self createCustomRangeAlert];
+        }];
+    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
+            
+        }];
+    [alertController addAction:defaultRange];
+    [alertController addAction:customRange];
+    [alertController addAction:cancelAction];
+    [self presentViewController:alertController animated:YES completion:nil];
+}
+
+- (void)createCustomRangeAlert {
+    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Custom Page Range" message:nil preferredStyle:UIAlertControllerStyleAlert];
+    
+    [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
+        textField.placeholder = @"such as:1,3-5,10";
+    }];
+    [alertController addAction:[UIAlertAction actionWithTitle:@"Done" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+        
+        self.dataModel.pageString = alertController.textFields.firstObject.text;
+        self.textView.rangeLabel.text = @"Page Range:Custom";
+    }]];
+    [alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+    }]];
+    [self presentViewController:alertController animated:YES completion:nil];
+}
+
+- (void)watermarkAdaption {
+    [_textPreview.watermarkLabel sizeToFit];
+    
+    [_textPreview.rotationBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
+        make.top.equalTo(_textPreview.watermarkLabel.mas_bottom).offset(-10);
+        make.width.equalTo(@20);
+        make.height.equalTo(@20);
+        make.left.equalTo(_textPreview.watermarkLabel.mas_right).offset(-10);
+    }];
+}
+
+- (void)tapWatermarkLabel:(UITapGestureRecognizer *)recognizer {
+    _alertController.view.hidden = NO;
+    _alertController.textFields.firstObject.text = _textPreview.watermarkLabel.text;
+    [self presentViewController:_alertController animated:true completion:nil];
+}
+
+- (void)panWatermarkLabel:(UIPanGestureRecognizer *)recognizer {
+    CGPoint point = [recognizer translationInView:_textPreview.documentView];
+    CGRect documentFrame = _textPreview.documentView.frame;
+    documentFrame.origin.x -= _textPreview.documentView.frame.origin.x;
+    documentFrame.origin.y -= _textPreview.documentView.frame.origin.y;
+    [_textPreview.watermarkLabel setCenter:CGPointMake(_textPreview.watermarkLabel.center.x + point.x, _textPreview.watermarkLabel.center.y + point.y)];
+    [_textPreview.rotationBtn setCenter:CGPointMake(_textPreview.rotationBtn.center.x + point.x, _textPreview.rotationBtn.center.y + point.y)];
+    if (!CGRectContainsRect(documentFrame,_textPreview.watermarkLabel.frame)) {
+        [_textPreview.watermarkLabel setCenter:CGPointMake(_textPreview.watermarkLabel.center.x - point.x, _textPreview.watermarkLabel.center.y - point.y)];
+        [_textPreview.rotationBtn setCenter:CGPointMake(_textPreview.rotationBtn.center.x - point.x, _textPreview.rotationBtn.center.y - point.y)];
     }
+    
+    _dataModel.tx = _textPreview.watermarkLabel.frame.origin.x - (_textPreview.documentView.center.x - _textPreview.documentView.frame.origin.x);
+    _dataModel.ty = _textPreview.documentView.center.y - _textPreview.documentView.frame.origin.y - _textPreview.watermarkLabel.frame.origin.y;
+    [recognizer setTranslation:CGPointZero inView:_textPreview.documentView];
+}
+
+- (void)rotationWatermarkLabel:(UIPanGestureRecognizer *)recognizer {
+    
+    CGPoint point = [recognizer translationInView:_textPreview];
+    CGFloat radian = atan2(point.x + _textPreview.center.x - _textPreview.watermarkLabel.center.x,point.y + _textPreview.center.y - _textPreview.watermarkLabel.center.y);
+    _textPreview.watermarkLabel.transform = CGAffineTransformMakeRotation(-radian);
+    
+    _dataModel.watermarkRotation = (-radian) * 180 / M_PI;
 }
 
 @end

+ 1 - 1
PDFViewer/Controller/CPDFViewController.h

@@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
 
 - (instancetype)initWithPath:(NSString *)inPath;
 - (void)createView;
-- (void)createFrame;
+- (void)addConstraint;
 
 @end
 

+ 124 - 24
PDFViewer/Controller/CPDFViewController.m

@@ -19,16 +19,16 @@
 #import "CPDFDataModel.h"
 #import "Masonry.h"
 
-#define KSCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width
-#define KSCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height
 
 @interface CPDFViewController () <UIActionSheetDelegate>
 
 @property (nonatomic,strong) CPDFTextViewController *textViewController;
 @property (nonatomic,strong) CPDFImageViewController *imageViewController;
 @property (nonatomic,strong) CPDFView *pdfView;
+@property (nonatomic,strong) CPDFDocument *pdfDocument;
 @property (nonatomic,strong) CPDFWatermark *textWatermark;
 @property (nonatomic,strong) CPDFWatermark *imageWatermark;
+@property (nonatomic,assign) CGSize imageSize;
 
 @end
 
@@ -45,15 +45,16 @@
     [super viewDidLoad];
     // Do any additional setup after loading the view.
     //add UIBarButtonItem in Navigation
-    self.navigationController.toolbarHidden = NO;
+    self.navigationController.toolbarHidden = YES;
     UIImage *btnMore = [UIImage imageNamed:@"btn_more"];
     UIBarButtonItem *ringhtBarItem = [[UIBarButtonItem alloc] initWithImage:btnMore style:UIBarButtonItemStylePlain target:self action:@selector(onClickedOkbtn)];
     self.navigationItem.rightBarButtonItem = ringhtBarItem;
+    
     //setting URL
     NSURL *url = [NSURL fileURLWithPath:_path];
-    CPDFDocument *document = [[CPDFDocument alloc] initWithURL:url];
+    _pdfDocument = [[CPDFDocument alloc] initWithURL:url];
     _pdfView = [[CPDFView alloc] initWithFrame:self.view.bounds];
-    _pdfView.document = document;
+    _pdfView.document = _pdfDocument;
     _pdfView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
     [self.view addSubview:_pdfView];
 }
@@ -79,14 +80,14 @@
     [self.view addSubview:_imageViewController.view];
     
     CPDFPage *pdfPage = [_pdfView.document pageAtIndex:0];
-      CGSize size = [_pdfView.document pageSizeAtIndex:0];
-    _textViewController.textPreview.documentView.image = [pdfPage thumbnailOfSize:size];
-    _imageViewController.imagePreview.documentView.image = [pdfPage thumbnailOfSize:size];
+      _imageSize = [_pdfView.document pageSizeAtIndex:0];
+    _textViewController.textPreview.documentView.image = [pdfPage thumbnailOfSize:_imageSize];
+    _imageViewController.imagePreview.documentView.image = [pdfPage thumbnailOfSize:_imageSize];
     _imageViewController.view.hidden = YES;
     _pdfView.hidden = YES;
     
-    _textWatermark = [[CPDFWatermark alloc] initWithDocument:_pdfView.document type:CPDFWatermarkTypeText];
-    _imageWatermark = [[CPDFWatermark alloc] initWithDocument:_pdfView.document type:CPDFWatermarkTypeImage];
+    _textWatermark = [[CPDFWatermark alloc] initWithDocument:_pdfDocument type:CPDFWatermarkTypeText];
+    _imageWatermark = [[CPDFWatermark alloc] initWithDocument:_pdfDocument type:CPDFWatermarkTypeImage];
 }
 
 - (void)segmentedAction:(UISegmentedControl *)sender {
@@ -104,29 +105,92 @@
     }
 }
 
-- (void)createFrame {
-    NSSet *set = [UIApplication sharedApplication].connectedScenes;
-    UIWindowScene *windowScene = [set anyObject];
-    UIStatusBarManager *statusBarManager = windowScene.statusBarManager;
-    _segmentedControl.frame = CGRectMake(0, statusBarManager.statusBarFrame.size.height + self.navigationController.navigationBar.frame.size
-                                         .height, KSCREEN_WIDTH, KSCREEN_HEIGHT / 20);
-    _segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
+- (void)addConstraint {
+    
+    [_segmentedControl mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.top.equalTo(self.navigationController.navigationBar.mas_bottom).offset(0);
+        make.width.equalTo(self.view.mas_width);
+        make.height.equalTo(@(self.view.bounds.size.height / 20));
+    }];
     
-    UIEdgeInsets padding = UIEdgeInsetsMake(statusBarManager.statusBarFrame.size.height + self.navigationController.navigationBar.frame.size
-                                            .height + KSCREEN_HEIGHT / 20, 0, 0, 0);
     [_textViewController.view mas_makeConstraints:^(MASConstraintMaker *make) {
-        make.edges.equalTo(self.view).with.insets(padding);
+        make.top.equalTo(_segmentedControl.mas_bottom).offset(0);
+        make.width.equalTo(_segmentedControl.mas_width);
+        make.bottom.equalTo(self.view).offset(0);
     }];
     [_imageViewController.view mas_makeConstraints:^(MASConstraintMaker *make) {
-        make.edges.equalTo(self.view).with.insets(padding);
+        make.top.equalTo(_segmentedControl.mas_bottom).offset(0);
+        make.width.equalTo(_segmentedControl.mas_width);
+        make.bottom.equalTo(self.view).offset(0);
+    }];
+    [_textViewController.textPreview.documentView mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.centerX.equalTo(_textViewController.textPreview.mas_centerX);
+        make.centerY.equalTo(_textViewController.textPreview.mas_centerY);
+        make.width.equalTo(@(_imageSize.width / 2));
+        make.height.equalTo(@(_imageSize.height / 2));
+    }];
+    [_imageViewController.imagePreview.documentView mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.centerX.equalTo(_imageViewController.imagePreview.mas_centerX);
+        make.centerY.equalTo(_imageViewController.imagePreview.mas_centerY);
+        make.width.equalTo(@(_imageSize.width / 2));
+        make.height.equalTo(@(_imageSize.height / 2));
     }];
 }
 
+- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
+    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
+    if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) {
+        
+        if (_imageSize.width > _imageSize.height) {
+            [_textViewController.textPreview.documentView mas_makeConstraints:^(MASConstraintMaker *make) {
+                make.centerX.equalTo(_textViewController.textPreview.mas_centerX);
+                make.centerY.equalTo(_textViewController.textPreview.mas_centerY);
+                make.width.equalTo(@(_imageSize.width / 3.1));
+                make.height.equalTo(@(_imageSize.height / 2.6));
+            }];
+            [_imageViewController.imagePreview.documentView mas_makeConstraints:^(MASConstraintMaker *make) {
+                make.centerX.equalTo(_imageViewController.imagePreview.mas_centerX);
+                make.centerY.equalTo(_imageViewController.imagePreview.mas_centerY);
+                make.width.equalTo(@(_imageSize.width / 3.1));
+                make.height.equalTo(@(_imageSize.height / 2.6));
+            }];
+        } else {
+            [_textViewController.textPreview.documentView mas_makeConstraints:^(MASConstraintMaker *make) {
+                make.centerX.equalTo(_textViewController.textPreview.mas_centerX);
+                make.centerY.equalTo(_textViewController.textPreview.mas_centerY);
+                make.width.equalTo(@(_imageSize.width / 2.4));
+                make.height.equalTo(@(_imageSize.height / 2.9));
+            }];
+            [_imageViewController.imagePreview.documentView mas_makeConstraints:^(MASConstraintMaker *make) {
+                make.centerX.equalTo(_imageViewController.imagePreview.mas_centerX);
+                make.centerY.equalTo(_imageViewController.imagePreview.mas_centerY);
+                make.width.equalTo(@(_imageSize.width / 2.4));
+                make.height.equalTo(@(_imageSize.height / 2.9));
+            }];
+        }
+        
+    } else if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) {
+        
+        [_textViewController.textPreview.documentView mas_remakeConstraints:^(MASConstraintMaker *make) {
+            make.centerX.equalTo(_textViewController.textPreview.mas_centerX);
+            make.centerY.equalTo(_textViewController.textPreview.mas_centerY);
+            make.width.equalTo(@(_imageSize.width / 2));
+            make.height.equalTo(@(_imageSize.height / 2));
+        }];
+        [_imageViewController.imagePreview.documentView mas_remakeConstraints:^(MASConstraintMaker *make) {
+            make.centerX.equalTo(_imageViewController.imagePreview.mas_centerX);
+            make.centerY.equalTo(_imageViewController.imagePreview.mas_centerY);
+            make.width.equalTo(@(_imageSize.width / 2));
+            make.height.equalTo(@(_imageSize.height / 2));
+        }];
+    }
+}
+
 - (void)onClickedOkbtn {
     UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
     UIAlertAction *addWatermarkAction = [UIAlertAction actionWithTitle:@"Add Watermark" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
         [self createView];
-        [self createFrame];
+        [self addConstraint];
         UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(onClickedDoneBtn)];
         self.navigationItem.rightBarButtonItem = doneBtn;
         }];
@@ -134,7 +198,7 @@
             NSLog(@"addHeaderfooterAction");
         }];
     UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-            NSLog(@"Cancel Action");
+            
         }];
     [alertController addAction:addWatermarkAction];
     [alertController addAction:addHeaderfooterAction];
@@ -151,17 +215,53 @@
     _segmentedControl.hidden = YES;
     
     if (_segmentedControl.selectedSegmentIndex == 0) {
-        _textWatermark.text = @"Watermark";
+        
+        _textWatermark.text = _textViewController.dataModel.text;
         _textWatermark.textColor = _textViewController.dataModel.textColor;
         _textWatermark.opacity = _textViewController.dataModel.watermarkOpacity;
         _textWatermark.scale = _textViewController.dataModel.watermarkScale;
         _textWatermark.isTilePage = _textViewController.dataModel.isTile;
+        _textWatermark.tx = _textViewController.dataModel.tx;
+        _textWatermark.ty = _textViewController.dataModel.ty;
+        _textWatermark.rotation = _textViewController.dataModel.watermarkRotation;
+        
+        if (_textWatermark.isTilePage) {
+            _textWatermark.verticalSpacing = [_textViewController.textView.verticalField.text floatValue];
+            _textWatermark.horizontalSpacing = [_textViewController.textView.horizontalField.text floatValue];
+        }
+        
+        if (_textViewController.dataModel.pageString) {
+            _textWatermark.pageString = _textViewController.dataModel.pageString;
+        }
+        
         [_pdfView.document addWatermark:_textWatermark];
+        [_pdfView layoutDocumentView];
+//        NSURL *url = [NSURL fileURLWithPath:_path];
+//        [_pdfView.document writeToURL:url];
         
     } else {
         
+        _imageWatermark.image = [UIImage imageNamed:_imageViewController.dataModel.imagePath];
+        _imageWatermark.opacity = _imageViewController.dataModel.watermarkOpacity;
+        _imageWatermark.scale = _imageViewController.dataModel.watermarkScale;
+        _imageWatermark.isTilePage = _imageViewController.dataModel.isTile;
+        _imageWatermark.tx = _imageViewController.dataModel.tx;
+        _imageWatermark.ty = _imageViewController.dataModel.ty;
+        _imageWatermark.rotation = _imageViewController.dataModel.watermarkRotation;
+        
+        if (_imageWatermark.isTilePage) {
+            _imageWatermark.verticalSpacing = [_imageViewController.imageView.verticalField.text floatValue];
+            _imageWatermark.horizontalSpacing = [_imageViewController.imageView.horizontalField.text floatValue];
+        }
+        
+        if (_imageViewController.dataModel.pageString) {
+            _imageWatermark.pageString = _imageViewController.dataModel.pageString;
+        }
         
         [_pdfView.document addWatermark:_imageWatermark];
+        [_pdfView layoutDocumentView];
+//        NSURL *url = [NSURL fileURLWithPath:_path];
+//        [_pdfView.document writeContentToURL:url];
     }
 }
 

+ 1 - 3
PDFViewer/Model/CPDFDataModel.h

@@ -18,12 +18,10 @@ NS_ASSUME_NONNULL_BEGIN
 @property (nonatomic,assign) CGFloat watermarkOpacity;
 @property (nonatomic,assign) CGFloat watermarkScale;
 @property (nonatomic,assign) BOOL isTile;
-@property (nonatomic,assign) NSRange pageRange;
+@property (nonatomic,assign) NSString *pageString;
 @property (nonatomic,assign) CGFloat tx;
 @property (nonatomic,assign) CGFloat ty;
 @property (nonatomic,assign) CGFloat watermarkRotation;
-@property (nonatomic,assign) CGFloat tileVerticalSpacing;
-@property (nonatomic,assign) CGFloat tileHorizontalSpacing;
 
 @property (nonatomic,copy) NSString *imagePath;
 

+ 1 - 0
PDFViewer/View/CPDFImagePreview.h

@@ -14,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
 @property (nonatomic,strong) UIImageView *watermarkView;
 @property (nonatomic,strong) UIButton *rotationBtn;
 @property (nonatomic,strong) UIImageView *documentView;
+@property (nonatomic,assign) CGRect watermarkFrame;
 
 @end
 

+ 18 - 16
PDFViewer/View/CPDFImagePreview.m

@@ -8,6 +8,8 @@
 #import "CPDFImagePreview.h"
 #import "Masonry.h"
 
+BOOL gImagePreviewIsFirstLayout = YES;
+
 @implementation CPDFImagePreview
 
 - (instancetype)initWithFrame:(CGRect)frame
@@ -19,31 +21,32 @@
 
         [self addSubview:_documentView];
         [_documentView addSubview:_watermarkView];
-        [_documentView addSubview:_rotationBtn];
+        [_watermarkView addSubview:_rotationBtn];
     }
     return self;
 }
 
 - (void)layoutSubviews {
     [super layoutSubviews];
-    [_watermarkView mas_makeConstraints:^(MASConstraintMaker *make) {
-        make.center.equalTo(self);
-        make.centerX.equalTo(self);
-        make.centerY.equalTo(self);
-        make.width.equalTo(@100);
-        make.height.equalTo(@100);
-    }];
-    _watermarkView.layer.borderColor = UIColor.blackColor.CGColor;
-    _watermarkView.layer.borderWidth = 2;
-    _watermarkView.image = [UIImage imageNamed:@"btn_selected"];
+    
+    _watermarkView.layer.borderColor = UIColor.blueColor.CGColor;
+    _watermarkView.layer.borderWidth = 1;
+    [_watermarkView sizeToFit];
+    _watermarkView.contentMode = UIViewContentModeScaleAspectFit;
+    
+    if (gImagePreviewIsFirstLayout) {
+        CGRect frame = _watermarkView.frame;
+        frame.origin = CGPointMake(_documentView.bounds.size.width / 2 - _watermarkView.frame.size.width / 2, _documentView.bounds.size.height / 2 - _watermarkView.frame.size.height / 2);
+        _watermarkFrame = frame;
+        gImagePreviewIsFirstLayout = NO;
+    }
+    _watermarkView.frame = _watermarkFrame;
     
     [_rotationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
-        make.top.equalTo(self.watermarkView).offset(90);
-        make.bottom.equalTo(self.watermarkView).offset(10);
-        make.right.equalTo(self.watermarkView).offset(10);
-        make.left.equalTo(self.watermarkView).offset(90);
+        make.top.equalTo(_watermarkView.mas_bottom).offset(-10);
         make.width.equalTo(@20);
         make.height.equalTo(@20);
+        make.left.equalTo(_watermarkView.mas_right).offset(-10);
     }];
     
     _rotationBtn.layer.cornerRadius = 10;
@@ -51,7 +54,6 @@
     _rotationBtn.layer.borderColor = UIColor.blueColor.CGColor;
     [_rotationBtn setBackgroundImage:[UIImage imageNamed:@"btn_selected"] forState:UIControlStateNormal];
     
-    _documentView.frame = self.bounds;
 }
 
 @end

+ 1 - 0
PDFViewer/View/CPDFImageView.h

@@ -24,6 +24,7 @@ NS_ASSUME_NONNULL_BEGIN
 @property (nonatomic,strong) UILabel *verticalLabel;
 @property (nonatomic,strong) UILabel *horizontalLabel;
 @property (nonatomic,strong) UILabel *imageLabel;
+@property (nonatomic,strong) UIButton *pageBtn;
 
 - (void)createView;
 - (void)createFrame;

+ 61 - 27
PDFViewer/View/CPDFImageView.m

@@ -8,10 +8,6 @@
 #import "CPDFImageView.h"
 #import "Masonry.h"
 
-#define KSCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width
-#define KSCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height
-
-
 @implementation CPDFImageView
 
 - (instancetype)initWithFrame:(CGRect)frame {
@@ -27,7 +23,7 @@
 - (void)layoutSubviews {
     [super layoutSubviews];
     [self createFrame];
-//    [self addConstraint];
+    [self addConstraint];
 }
 
 - (void)createView {
@@ -51,6 +47,7 @@
     _horizontalLabel = [[UILabel alloc] init];
     _imageLabel = [[UILabel alloc] init];
     _selectBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
+    _pageBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
     
     [self addSubview:_opacitySlider];
     [self addSubview:_sizeLabel];
@@ -65,6 +62,7 @@
     [self addSubview:_horizontalLabel];
     [self addSubview:_imageLabel];
     [self addSubview:_selectBtn];
+    [self addSubview:_pageBtn];
     
     [self setBackgroundColor:[UIColor whiteColor]];
     
@@ -72,40 +70,76 @@
 
 - (void)createFrame {
     // y -- 40   height -- 30
-    _opacitySlider.frame = CGRectMake(90, 40, KSCREEN_WIDTH - 100, 30);
-    _imageScaleSlider.frame = CGRectMake(90, 80, KSCREEN_WIDTH - 100, 30);
     _tileSwitch.frame = CGRectMake(100, 160, 10, 10);
-    _rangeLabel.frame = CGRectMake(10, 120, 100, 30);
+    _rangeLabel.frame = CGRectMake(10, 120, 180, 30);
     _tileLabel.frame = CGRectMake(10, 160, 100, 30);
     _sizeLabel.frame = CGRectMake(10, 80, 90, 30);
     _opacityLabel.frame = CGRectMake(10, 40, 90, 30);
-    _verticalLabel.frame = CGRectMake(270, 160, 20, 30);
-    _verticalField.frame = CGRectMake(295, 160, 80, 30);
-    _horizontalLabel.frame = CGRectMake(165, 160, 20, 30);
-    _horizontalField.frame = CGRectMake(185, 160, 80, 30);
-    _selectBtn.frame = CGRectMake(150, 2, 227, 35);
     _imageLabel.frame = CGRectMake(10, 5, 150, 30);
     
     _selectBtn.layer.borderWidth = 1.0;
-    _selectBtn.layer.borderColor = UIColor.blackColor.CGColor;
+    _selectBtn.layer.borderColor = UIColor.systemGray4Color.CGColor;
     [_selectBtn setTitle:@"Select Image" forState:UIControlStateNormal];
     [_selectBtn setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
     _selectBtn.layer.cornerRadius = 7;
+    
+    _pageBtn.layer.borderWidth = 1.0;
+    _pageBtn.layer.borderColor = UIColor.systemGray4Color.CGColor;
+    [_pageBtn setTitle:@"Page Range" forState:UIControlStateNormal];
+    [_pageBtn setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
+    _pageBtn.layer.cornerRadius = 7;
 }
 
-//- (void)addConstraint {
-//    [self.opacityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
-//        make.left.equalTo(self).offset(10);
-//        make.top.equalTo(self).offset(40);
-//        make.right.equalTo(self.mas_right).offset(-10);
-//    }];
-//    [self.opacitySlider mas_makeConstraints:^(MASConstraintMaker *make) {
-//        make.left.equalTo(self.mas_left).offset(90);
-//        make.top.equalTo(self.mas_top).offset(40);
-//        make.width.equalTo(@(KSCREEN_WIDTH - 100));
-//        make.height.equalTo(@30);
-//    }];
-//}
+- (void)addConstraint {
+    [_verticalField mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.right.equalTo(self.mas_right).offset(-15);
+        make.bottom.equalTo(self.mas_bottom).offset(-15);
+        make.width.equalTo(@80);
+        make.height.equalTo(@30);
+    }];
+    [_verticalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.right.equalTo(self.mas_right).offset(-95);
+        make.bottom.equalTo(self.mas_bottom).offset(-15);
+        make.width.equalTo(@20);
+        make.height.equalTo(@30);
+    }];
+    [_horizontalField mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.right.equalTo(self.mas_right).offset(-115);
+        make.bottom.equalTo(self.mas_bottom).offset(-15);
+        make.width.equalTo(@80);
+        make.height.equalTo(@30);
+    }];
+    [_horizontalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.right.equalTo(self.mas_right).offset(-195);
+        make.bottom.equalTo(self.mas_bottom).offset(-15);
+        make.width.equalTo(@20);
+        make.height.equalTo(@30);
+    }];
+    [_selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.right.equalTo(self.mas_right).offset(-15);
+        make.top.equalTo(self.mas_top).offset(2);
+        make.left.equalTo(_horizontalField.mas_left);
+        make.height.equalTo(@35);
+    }];
+    [_imageScaleSlider mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.right.equalTo(self.mas_right).offset(-15);
+        make.left.equalTo(_sizeLabel.mas_right).offset(0);
+        make.top.equalTo(self.mas_top).offset(80);
+        make.height.equalTo(@30);
+    }];
+    [_opacitySlider mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.right.equalTo(self.mas_right).offset(-15);
+        make.left.equalTo(_opacityLabel.mas_right).offset(0);
+        make.top.equalTo(self.mas_top).offset(40);
+        make.height.equalTo(@30);
+    }];
+    [_pageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.right.equalTo(self.mas_right).offset(-15);
+        make.top.equalTo(self.mas_top).offset(115);
+        make.left.equalTo(_horizontalField.mas_left);
+        make.height.equalTo(@35);
+    }];
+}
 
 - (void)assignData {
     _rangeLabel.text = @"Page Range";

+ 0 - 22
PDFViewer/View/CPDFPageRangeDropDownList.h

@@ -1,22 +0,0 @@
-//
-//  CPDFPageRangeDropDownList.h
-//  PDFViewer
-//
-//  Created by kdan on 2022/11/18.
-//
-
-#import <UIKit/UIKit.h>
-
-NS_ASSUME_NONNULL_BEGIN
-
-@interface CPDFPageRangeDropDownList : UIView
-
-@property (nonatomic,retain)UITextField *textField;
-@property (nonatomic,retain)NSArray* list;
-@property (nonatomic,retain)UITableView* listView;
-@property (nonatomic,retain)UIColor *lineColor,*listBgColor;
-@property (nonatomic,assign)UITextBorderStyle borderStyle;
-
-@end
-
-NS_ASSUME_NONNULL_END

+ 0 - 13
PDFViewer/View/CPDFPageRangeDropDownList.m

@@ -1,13 +0,0 @@
-//
-//  CPDFPageRangeDropDownList.m
-//  PDFViewer
-//
-//  Created by kdan on 2022/11/18.
-//
-
-#import "CPDFPageRangeDropDownList.h"
-
-@implementation CPDFPageRangeDropDownList
-
-
-@end

+ 19 - 24
PDFViewer/View/CPDFTextPreview.m

@@ -8,6 +8,8 @@
 #import "CPDFTextPreview.h"
 #import "Masonry.h"
 
+BOOL gTextPreviewIsFirstLayout = YES;
+
 @implementation CPDFTextPreview
 
 - (instancetype)initWithFrame:(CGRect)frame
@@ -16,10 +18,10 @@
         _watermarkLabel = [[UILabel alloc] init];
         _rotationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
         _documentView = [[UIImageView alloc] init];
-
+        
         [self addSubview:_documentView];
         [_documentView addSubview:_watermarkLabel];
-        [_documentView addSubview:_rotationBtn];
+        [_watermarkLabel addSubview:_rotationBtn];
     }
     return self;
 }
@@ -27,34 +29,27 @@
 - (void)layoutSubviews {
     [super layoutSubviews];
 
-    _watermarkLabel.layer.borderWidth = 2;
-    _watermarkLabel.layer.borderColor = UIColor.blackColor.CGColor;
-    _watermarkLabel.text = @"Watermark";
-    _watermarkLabel.textColor = UIColor.redColor;
-    _watermarkLabel.font = [UIFont systemFontOfSize:24];
-    
+    _watermarkLabel.layer.borderWidth = 1;
+    _watermarkLabel.layer.borderColor = UIColor.blueColor.CGColor;
+
     [_watermarkLabel sizeToFit];
-    CGRect frame = _watermarkLabel.frame;
-    frame.origin = CGPointMake(self.bounds.size.width / 2 - _watermarkLabel.frame.size.width / 2, self.bounds.size.height / 2 - _watermarkLabel.frame.size.height / 2);
-    _watermarkLabel.frame = frame;
-    
+    if (gTextPreviewIsFirstLayout) {
+        CGRect frame = _watermarkLabel.frame;
+        frame.origin = CGPointMake(_documentView.bounds.size.width / 2 - _watermarkLabel.frame.size.width / 2, _documentView.bounds.size.height / 2 - _watermarkLabel.frame.size.height / 2);
+            _watermarkLabel.frame = frame;
+        gTextPreviewIsFirstLayout = NO;
+    }
     _rotationBtn.layer.cornerRadius = 10;
     _rotationBtn.layer.masksToBounds = YES;
     _rotationBtn.layer.borderColor = UIColor.blueColor.CGColor;
     [_rotationBtn setBackgroundImage:[UIImage imageNamed:@"btn_selected"] forState:UIControlStateNormal];
     
-//    [_rotationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
-//        make.top.equalTo(self.watermarkLabel).offset(self.watermarkLabel.frame.size.height - 10);
-//        make.bottom.equalTo(self.watermarkLabel).offset(10);
-//        make.right.equalTo(self.watermarkLabel).offset(20);
-//        make.left.equalTo(self.watermarkLabel).offset(self.watermarkLabel.frame.size.width);
-//        make.width.equalTo(@20);
-//        make.height.equalTo(@20);
-//    }];
-    _rotationBtn.frame = CGRectMake(self.bounds.size.width / 2 + _watermarkLabel.frame.size.width / 2 - 10, self.bounds.size.height / 2 + _watermarkLabel.frame.size.height / 2 - 10, 20, 20);
-    
-    _documentView.frame = self.bounds;
-    _documentView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
+    [_rotationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.top.equalTo(_watermarkLabel.mas_bottom).offset(-10);
+        make.width.equalTo(@20);
+        make.height.equalTo(@20);
+        make.left.equalTo(_watermarkLabel.mas_right).offset(-10);
+    }];
 }
 
 @end

+ 2 - 0
PDFViewer/View/CPDFTextView.h

@@ -12,6 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
 @interface CPDFTextView : UIView
 
 @property (nonatomic,strong) UIButton *colorBtn;
+@property (nonatomic,strong) UILabel *colorLabel;
 @property (nonatomic,strong) UISlider *textScaleSlider;
 @property (nonatomic,strong) UISlider *opacitySlider;
 @property (nonatomic,strong) UISwitch *tileSwitch;
@@ -23,6 +24,7 @@ NS_ASSUME_NONNULL_BEGIN
 @property (nonatomic,strong) UITextField *horizontalField;
 @property (nonatomic,strong) UILabel *verticalLabel;
 @property (nonatomic,strong) UILabel *horizontalLabel;
+@property (nonatomic,strong) UIButton *pageBtn;
 
 @property (nonatomic,strong) NSMutableArray *colorArray;
 

+ 70 - 27
PDFViewer/View/CPDFTextView.m

@@ -8,9 +8,6 @@
 #import "CPDFTextView.h"
 #import "Masonry.h"
 
-#define KSCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width
-#define KSCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height
-
 #define KBUTTON_WIDTH 28
 #define KBUTTON_HEIGHT 28
 
@@ -29,7 +26,7 @@
 - (void)layoutSubviews {
     [super layoutSubviews];
     [self createFrame];
-//    [self addConstraint];
+    [self addConstraint];
 }
 
 - (void)createView {
@@ -41,6 +38,7 @@
     _tileLabel = [[UILabel alloc] init];
     _textLabel = [[UILabel alloc] init];
     _opacityLabel = [[UILabel alloc] init];
+    _colorLabel = [[UILabel alloc] init];
     
     _verticalField = [[UITextField alloc] init];
     _verticalField.borderStyle = UITextBorderStyleRoundedRect;
@@ -51,6 +49,7 @@
     _horizontalField.borderStyle = UITextBorderStyleRoundedRect;
     
     _horizontalLabel = [[UILabel alloc] init];
+    _pageBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
     
     _colorArray = [NSMutableArray array];
     for (NSInteger i = 0; i < 8; ++i) {
@@ -71,6 +70,8 @@
     [self addSubview:_verticalField];
     [self addSubview:_horizontalField];
     [self addSubview:_horizontalLabel];
+    [self addSubview:_colorLabel];
+    [self addSubview:_pageBtn];
     
     [self setBackgroundColor:[UIColor whiteColor]];
     
@@ -78,22 +79,14 @@
 
 - (void)createFrame {
     // y -- 40   height -- 30
-    _opacitySlider.frame = CGRectMake(90, 40, KSCREEN_WIDTH - 100, 30);
-    _textScaleSlider.frame = CGRectMake(90, 80, KSCREEN_WIDTH - 100, 30);
     _tileSwitch.frame = CGRectMake(100, 160, 10, 10);
-    _rangeLabel.frame = CGRectMake(10, 120, 100, 30);
+    _rangeLabel.frame = CGRectMake(10, 120, 180, 30);
     _tileLabel.frame = CGRectMake(10, 160, 100, 30);
     _textLabel.frame = CGRectMake(10, 80, 90, 30);
     _opacityLabel.frame = CGRectMake(10, 40, 90, 30);
-    _verticalLabel.frame = CGRectMake(270, 160, 20, 30);
-    _verticalField.frame = CGRectMake(295, 160, 80, 30);
-    _horizontalLabel.frame = CGRectMake(165, 160, 20, 30);
-    _horizontalField.frame = CGRectMake(185, 160, 80, 30);
+    _colorLabel.frame = CGRectMake(10, 5, 50, 30);
     
-    NSInteger offset = 10;
     for (NSInteger i = 0; i < _colorArray.count; i++) {
-        [[self colorArray][i] setFrame:CGRectMake(offset, 5, KBUTTON_WIDTH, KBUTTON_HEIGHT)];
-        offset += 50;
         [[[self colorArray][i] layer] setCornerRadius:KBUTTON_WIDTH / 2];
         [[[self colorArray][i] layer] setMasksToBounds:YES];
     }
@@ -106,21 +99,70 @@
     [_colorArray[5] setBackgroundColor:[UIColor brownColor]];
     [_colorArray[6] setBackgroundColor:[UIColor purpleColor]];
     [_colorArray[7] setBackgroundColor:[UIColor grayColor]];
+    
+    _pageBtn.layer.borderWidth = 1.0;
+    _pageBtn.layer.borderColor = UIColor.systemGray4Color.CGColor;
+    [_pageBtn setTitle:@"Page Range" forState:UIControlStateNormal];
+    [_pageBtn setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
+    _pageBtn.layer.cornerRadius = 7;
 }
 
-//- (void)addConstraint {
-//    [self.opacityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
-//        make.left.equalTo(self).offset(10);
-//        make.top.equalTo(self).offset(40);
-//        make.right.equalTo(self.mas_right).offset(-10);
-//    }];
-//    [self.opacitySlider mas_makeConstraints:^(MASConstraintMaker *make) {
-//        make.left.equalTo(self.mas_left).offset(90);
-//        make.top.equalTo(self.mas_top).offset(40);
-//        make.width.equalTo(@(KSCREEN_WIDTH - 100));
-//        make.height.equalTo(@30);
-//    }];
-//}
+- (void)addConstraint {
+    [_verticalField mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.right.equalTo(self.mas_right).offset(-15);
+        make.bottom.equalTo(self.mas_bottom).offset(-15);
+        make.width.equalTo(@80);
+        make.height.equalTo(@30);
+    }];
+    [_verticalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.right.equalTo(self.mas_right).offset(-95);
+        make.bottom.equalTo(self.mas_bottom).offset(-15);
+        make.width.equalTo(@20);
+        make.height.equalTo(@30);
+    }];
+    [_horizontalField mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.right.equalTo(self.mas_right).offset(-115);
+        make.bottom.equalTo(self.mas_bottom).offset(-15);
+        make.width.equalTo(@80);
+        make.height.equalTo(@30);
+    }];
+    [_horizontalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.right.equalTo(self.mas_right).offset(-195);
+        make.bottom.equalTo(self.mas_bottom).offset(-15);
+        make.width.equalTo(@20);
+        make.height.equalTo(@30);
+    }];
+    [_textScaleSlider mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.right.equalTo(self.mas_right).offset(-15);
+        make.left.equalTo(_textLabel.mas_right).offset(0);
+        make.top.equalTo(self.mas_top).offset(80);
+        make.height.equalTo(@30);
+    }];
+    [_opacitySlider mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.right.equalTo(self.mas_right).offset(-15);
+        make.left.equalTo(_opacityLabel.mas_right).offset(0);
+        make.top.equalTo(self.mas_top).offset(40);
+        make.height.equalTo(@30);
+    }];
+    
+    NSInteger offset = 10;
+    for (NSInteger i = 0; i < _colorArray.count; ++i) {
+        [_colorArray[i] mas_makeConstraints:^(MASConstraintMaker *make) {
+            make.right.equalTo(self.mas_right).offset( - offset);
+            make.top.equalTo(self.mas_top).offset(5);
+            make.width.equalTo(@KBUTTON_WIDTH);
+            make.height.equalTo(@KBUTTON_HEIGHT);
+        }];
+        offset += 40;
+    }
+    
+    [_pageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.right.equalTo(self.mas_right).offset(-15);
+        make.top.equalTo(self.mas_top).offset(115);
+        make.left.equalTo(_horizontalField.mas_left);
+        make.height.equalTo(@35);
+    }];
+}
 
 - (void)assignData {
     _rangeLabel.text = @"Page Range";
@@ -129,6 +171,7 @@
     _opacityLabel.text = @"Opacity";
     _verticalLabel.text = @"Y:";
     _horizontalLabel.text = @"X:";
+    _colorLabel.text = @"Color";
 }
 
 @end

BIN
PDFViewer/View/sources/pdfImage@2x.png