Browse Source

PDFTools(iOS)-自测(签名)

yangliuhua 1 year ago
parent
commit
afa7d1965a

+ 14 - 3
compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFFreeText/CPDFFreeTextViewController.m

@@ -300,7 +300,7 @@
         self.boldBtn.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
     }
 
-    self.sampleView.isBold = self.isBold;
+    self.sampleView.fontName = [self constructionFontname:self.baseName isBold:self.isBold isItalic:self.isItalic];
     [self.sampleView setNeedsDisplay];
     self.annotStyle.fontName = [self constructionFontname:self.baseName isBold:self.isBold isItalic:self.isItalic];
     if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
@@ -316,9 +316,9 @@
         self.italicBtn.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
     }
     
-    self.sampleView.isItalic = self.isItalic;
-    [self.sampleView setNeedsDisplay];
     self.annotStyle.fontName = [self constructionFontname:self.baseName isBold:self.isBold isItalic:self.isItalic];
+    self.sampleView.fontName = [self constructionFontname:self.baseName isBold:self.isBold isItalic:self.isItalic];
+    [self.sampleView setNeedsDisplay];
     
     if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
         [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
@@ -369,6 +369,17 @@
     }
 }
 
+#pragma mark - CPDFOpacitySliderViewDelegate
+
+- (void)opacitySliderView:(CPDFOpacitySliderView *)opacitySliderView opacity:(CGFloat)opacity {
+    self.sampleView.opcity = opacity;
+    self.annotStyle.opacity = opacity;
+    if (self.delegate && [self.delegate respondsToSelector:@selector(freeTextViewController:annotStyle:)]) {
+        [self.delegate freeTextViewController:self annotStyle:self.annotStyle];
+    }
+    [self.sampleView setNeedsDisplay];
+}
+
 #pragma mark - CPDFThicknessSliderViewDelegate
 
 - (void)thicknessSliderView:(CPDFThicknessSliderView *)thicknessSliderView thickness:(CGFloat)thickness {

+ 63 - 28
compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFSignature/CPDFSignatureEditViewController.m

@@ -18,7 +18,7 @@
 
 #import <compdfkit_tools/CPDFColorUtils.h>
 
-@interface CPDFSignatureEditViewController () <UIPopoverPresentationControllerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIColorPickerViewControllerDelegate, UITextFieldDelegate, CPDFColorSelectViewDelegate, CPDFColorPickerViewDelegate, CSignatureDrawViewDelegate>
+@interface CPDFSignatureEditViewController () <UIPopoverPresentationControllerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIColorPickerViewControllerDelegate, UITextFieldDelegate,UIGestureRecognizerDelegate, CPDFColorSelectViewDelegate, CPDFColorPickerViewDelegate, CSignatureDrawViewDelegate>
 
 @property (nonatomic, strong) CPDFColorSelectView *colorSelectView;
 
@@ -50,6 +50,10 @@
 
 @property (nonatomic, strong) UIButton *clearButton;
 
+@property (nonatomic, strong) UILabel *emptyLabel;
+
+@property (nonatomic, strong) UIView *headerView;
+
 @end
 
 @implementation CPDFSignatureEditViewController
@@ -58,15 +62,27 @@
 
 - (void)viewDidLoad {
     [super viewDidLoad];
-    // Do any additional setup after loading the view.
-    self.title = NSLocalizedString(@"Add Signature", nil);
+    // Do any additional setup after loading the view
+    
+    self.headerView = [[UIView alloc] init];
+    self.headerView.layer.borderColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1].CGColor;
+    self.headerView.layer.borderWidth = 1.0;
+    self.headerView.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
+    [self.view addSubview:self.headerView];
     
     NSArray *segmmentArray = [NSArray arrayWithObjects:NSLocalizedString(@"Draw", nil), NSLocalizedString(@"Text", nil), NSLocalizedString(@"Image", nil),nil];
     _segmentedControl = [[UISegmentedControl alloc] initWithItems:segmmentArray];
     _segmentedControl.selectedSegmentIndex = 0;
     _segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
     [_segmentedControl addTarget:self action:@selector(segmentedControlValueChanged_singature:) forControlEvents:UIControlEventValueChanged];
-    self.navigationItem.titleView = self.segmentedControl;
+    [self.view addSubview:self.segmentedControl];
+    
+    self.emptyLabel = [[UILabel alloc] init];
+    self.emptyLabel.font = [UIFont systemFontOfSize:27];
+    self.emptyLabel.textColor = [UIColor grayColor];
+    self.emptyLabel.text = NSLocalizedString(@"Signature Here", nil);
+    self.emptyLabel.textAlignment = NSTextAlignmentCenter;
+    [self.view addSubview:self.emptyLabel];
     
     self.signatureDrawTextView = [[CSignatureDrawView alloc] init];
     self.signatureDrawTextView.delegate = self;
@@ -107,17 +123,16 @@
     
     self.cacelButon = [[UIButton alloc] init];
     [self.cacelButon setTitle:NSLocalizedString(@"Cancel", nil) forState:UIControlStateNormal];
+    self.cacelButon.titleLabel.adjustsFontSizeToFitWidth = YES;
     [self.cacelButon setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
     [self.cacelButon addTarget:self action:@selector(buttonItemClicked_Cancel:) forControlEvents:UIControlEventTouchUpInside];
-    UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc] initWithCustomView:self.cacelButon];
-    self.navigationItem.leftBarButtonItem = cancelItem;
+    [self.headerView addSubview:self.cacelButon];
     
     self.saveButton = [[UIButton alloc] init];
     [self.saveButton setTitle:NSLocalizedString(@"Done", nil) forState:UIControlStateNormal];
     [self.saveButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
     [self.saveButton addTarget:self action:@selector(buttonItemClicked_Save:) forControlEvents:UIControlEventTouchUpInside];
-    UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithCustomView:self.saveButton];
-    self.navigationItem.rightBarButtonItem = doneItem;
+    [self.headerView addSubview:self.saveButton];
     
     self.bottomBorder = [CALayer layer];
     self.bottomBorder.backgroundColor = [UIColor blackColor].CGColor;
@@ -153,30 +168,26 @@
     self.selecIndex = CSignatureTopBarDefault;
     self.view.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
     [self createGestureRecognizer];
+    [self updatePreferredContentSizeWithTraitCollection:self.traitCollection];
 }
 
 - (void)viewWillLayoutSubviews {
     [super viewWillLayoutSubviews];
+    self.headerView.frame = CGRectMake(0, 0, self.view.frame.size.width, 150);
     self.colorPicker.frame = CGRectMake(0, self.view.frame.size.height/2, self.view.frame.size.width, self.view.frame.size.height/2);
-    self.segmentedControl.frame = CGRectMake(0, 40, 280, 30);
+    self.segmentedControl.frame = CGRectMake((self.view.frame.size.width - 220)/2, 10, 220, 30);
+    self.emptyLabel.frame = CGRectMake((self.view.frame.size.width - 200)/2, (self.view.frame.size.height - 50)/2, 200, 50);
    
     if (@available(iOS 11.0, *)) {
-        if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) {
-            self.colorSelectView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top, self.view.frame.size.width-self.view.safeAreaInsets.left-self.view.safeAreaInsets.right, 60);
-            self.thicknessView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top+90, self.view.frame.size.width-self.view.safeAreaInsets.left-self.view.safeAreaInsets.right, 60);
-            self.thicknessLabel.frame = CGRectMake(20, 15, 60, 30);
-            self.thicknessSlider.frame = CGRectMake(90, 0, self.thicknessView.bounds.size.width-110, 60);
-            self.signatureDrawTextView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top + 150, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height-self.view.safeAreaInsets.top-self.view.safeAreaInsets.bottom-150);
-            
-        } else {
-            self.colorSelectView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top-15, 380, 60);
-            self.thicknessView.frame = CGRectMake(self.view.safeAreaInsets.left+380, self.view.safeAreaInsets.top, self.view.frame.size.width-self.view.safeAreaInsets.left-self.view.safeAreaInsets.right-380, 60);
-            self.thicknessLabel.frame = CGRectMake(20, 15, 60, 30);
-            self.thicknessSlider.frame = CGRectMake(90, 0, self.thicknessView.bounds.size.width-110, 60);
-            self.signatureDrawTextView.frame = CGRectMake(self.view.safeAreaInsets.left, self.view.safeAreaInsets.top + 90, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height-self.view.safeAreaInsets.top-self.view.safeAreaInsets.bottom-90);
-        }
+        self.saveButton.frame = CGRectMake(self.view.frame.size.width - 60 - self.view.safeAreaInsets.right, 5, 50, 40);
+        self.cacelButon.frame = CGRectMake( self.view.safeAreaInsets.left+20, 5, 50, 40);
+        self.colorSelectView.frame = CGRectMake(self.view.safeAreaInsets.left, 50, self.view.frame.size.width-self.view.safeAreaInsets.left-self.view.safeAreaInsets.right, 60);
+        self.thicknessView.frame = CGRectMake(self.view.safeAreaInsets.left, 140, self.view.frame.size.width-self.view.safeAreaInsets.left-self.view.safeAreaInsets.right, 60);
+        self.thicknessLabel.frame = CGRectMake(20, 15, 60, 30);
+        self.thicknessSlider.frame = CGRectMake(90, 0, self.thicknessView.bounds.size.width-110, 60);
+        self.signatureDrawTextView.frame = CGRectMake(self.view.safeAreaInsets.left, 210, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height-self.view.safeAreaInsets.top-self.view.safeAreaInsets.bottom-150);
         
-        self.signatureDrawImageView.frame = self.signatureDrawTextView.frame;
+        self.signatureDrawImageView.frame = CGRectMake(self.view.safeAreaInsets.left, 50, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right, self.view.frame.size.height-self.view.safeAreaInsets.top-self.view.safeAreaInsets.bottom-150);
         self.createButton.frame = CGRectMake(self.view.frame.size.width - 70 - self.view.safeAreaInsets.right, self.view.frame.size.height - 100 - self.view.safeAreaInsets.bottom, 50, 50);
         self.clearButton.frame = CGRectMake(self.view.frame.size.width - 70 - self.view.safeAreaInsets.right, self.view.frame.size.height - 100 - self.view.safeAreaInsets.bottom, 50, 50);
     } else {
@@ -186,6 +197,8 @@
         self.signatureDrawImageView.frame = self.signatureDrawTextView.frame;
         self.createButton.frame = CGRectMake(self.view.frame.size.width - 70, self.view.frame.size.height - 100, 50, 50);
         self.clearButton.frame = CGRectMake(self.view.frame.size.width - 70, self.view.frame.size.height - 100, 50, 50);
+        self.saveButton.frame = CGRectMake(self.view.frame.size.width - 60, 5, 50, 40);
+        self.cacelButon.frame = CGRectMake(20, 5, 50, 40);
     }
     
     self.textField.frame = CGRectMake((self.view.frame.size.width - 300)/2, 200, 300, 100);
@@ -195,8 +208,17 @@
     [self.signatureDrawTextView signatureClear];
 }
 
+- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
+    [super willTransitionToTraitCollection:newCollection withTransitionCoordinator:coordinator];
+    [self updatePreferredContentSizeWithTraitCollection:newCollection];
+}
+
 #pragma mark - Private Methods
 
+- (void)updatePreferredContentSizeWithTraitCollection:(UITraitCollection *)traitCollection {
+    self.preferredContentSize = CGSizeMake(self.view.bounds.size.width, traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact ? 350 : 750);
+}
+
 - (void)createGestureRecognizer {
     [self.createButton setUserInteractionEnabled:YES];
 
@@ -233,6 +255,7 @@
             [self.delegate signatureEditViewController:self image:image];
         }
     } else if (CSignatureTopBarImage == self.selecIndex) {
+        [self.signatureDrawTextView signatureClear];
         UIImage *image = [self.signatureDrawImageView signatureImage];
         if (self.delegate && [self.delegate respondsToSelector:@selector(signatureEditViewController:image:)]) {
             [self.delegate signatureEditViewController:self image:image];
@@ -260,13 +283,17 @@
     if (self.segmentedControl.selectedSegmentIndex == 0) {
         self.colorSelectView.hidden = NO;
         self.signatureDrawTextView.hidden = NO;
-        self.signatureDrawImageView.hidden = YES;
-        self.textField.hidden = YES;
         self.selecIndex = CSignatureTopBarDefault;
         self.colorSelectView.hidden = NO;
-        self.createButton.hidden = YES;
         self.clearButton.hidden = NO;
         self.signatureDrawTextView.selectIndex = CSignatureDrawText;
+        self.emptyLabel.hidden = NO;
+        self.thicknessView.hidden = NO;
+        
+        self.signatureDrawImageView.hidden = YES;
+        self.createButton.hidden = YES;
+        self.textField.hidden = YES;
+        [self.textField resignFirstResponder];
     } else if (self.segmentedControl.selectedSegmentIndex == 1) {
         self.colorSelectView.hidden = NO;
         self.signatureDrawTextView.hidden = YES;
@@ -277,8 +304,10 @@
         self.createButton.hidden = YES;
         self.thicknessView.hidden = YES;
         self.clearButton.hidden = NO;
-        [self.textField resignFirstResponder];
+        self.emptyLabel.hidden = YES;
+        [self.textField becomeFirstResponder];
     } else if (self.segmentedControl.selectedSegmentIndex == 2) {
+        [self.textField resignFirstResponder];
         self.colorSelectView.hidden = YES;
         self.signatureDrawTextView.hidden = YES;
         self.signatureDrawImageView.hidden = NO;
@@ -289,6 +318,7 @@
         self.signatureDrawImageView.selectIndex = CSignatureDrawImage;
         self.thicknessView.hidden = YES;
         self.clearButton.hidden = YES;
+        self.emptyLabel.hidden = NO;
         [self.signatureDrawImageView setNeedsDisplay];
     }
 }
@@ -301,7 +331,11 @@
 - (void)buttonItemClicked_clear:(UIButton *)button {
     if (self.segmentedControl.selectedSegmentIndex == 0) {
         [self.signatureDrawTextView signatureClear];
+        self.emptyLabel.text = NSLocalizedString(@"Signature Here", nil);
+    } else if (self.segmentedControl.selectedSegmentIndex == 1) {
+        self.textField.text = @"";
     }
+    
 }
 
 #pragma mark - UITextFieldDelegate
@@ -449,6 +483,7 @@
 
 - (void)signatureDrawViewStart:(CSignatureDrawView *)signatureDrawView {
     [self.saveButton setTitleColor:[UIColor colorWithRed:20.0/255.0 green:96.0/255.0 blue:243.0/255.0 alpha:1.0] forState:UIControlStateNormal];
+    self.emptyLabel.text = @"";
 }
 
 @end

+ 23 - 10
compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFSignature/CPDFSignatureViewController.m

@@ -17,8 +17,9 @@
 #import "CPDFSignatureEditViewController.h"
 
 #import <compdfkit_tools/CPDFColorUtils.h>
+#import <compdfkit_tools/AAPLCustomPresentationController.h>
 
-@interface CPDFSignatureViewController () <UITableViewDelegate, UITableViewDataSource, CPDFSignatureViewCellDelegate>
+@interface CPDFSignatureViewController () <UITableViewDelegate, UITableViewDataSource, CPDFSignatureViewCellDelegate,CPDFSignatureEditViewControllerDelegate>
 
 @property (nonatomic, strong) UIButton *backBtn;
 
@@ -124,8 +125,6 @@
     [gestureRecognizer setTranslation:CGPointZero inView:self.view];
 }
 
-#pragma mark - Protect Methods
-
 - (void)updatePreferredContentSizeWithTraitCollection:(UITraitCollection *)traitCollection {
     self.preferredContentSize = CGSizeMake(self.view.bounds.size.width, traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact ? 350 : 660);
 }
@@ -133,18 +132,21 @@
 #pragma mark - Action
 
 - (void)buttonItemClicked_back:(id)sender {
-    if([self.delegate performSelector:@selector(signatureViewControllerDismiss:)]) {
+    [self dismissViewControllerAnimated:NO completion:nil];
+    if(self.delegate && [self.delegate respondsToSelector:@selector(signatureViewControllerDismiss:)]) {
         [self.delegate signatureViewControllerDismiss:self];
     }
-    [self dismissViewControllerAnimated:YES completion:^{
-    }];
 }
 
 - (void)buttonItemClicked_create:(id)sender {
-    [self dismissViewControllerAnimated:NO completion:nil];
-    if (self.delegate && [self.delegate respondsToSelector:@selector(signatureViewController:)]) {
-        [self.delegate signatureViewController:self];
-    }
+    AAPLCustomPresentationController *presentationController NS_VALID_UNTIL_END_OF_SCOPE;
+    CPDFSignatureEditViewController *editVC = [[CPDFSignatureEditViewController alloc] init];
+    
+    editVC.delegate = self;
+    
+    presentationController = [[AAPLCustomPresentationController alloc] initWithPresentedViewController:editVC presentingViewController:self];
+    editVC.transitioningDelegate = presentationController;
+    [self presentViewController:editVC animated:YES completion:nil];
 }
 
 #pragma mark - UITableViewDataSource
@@ -197,4 +199,15 @@
     [self.tableView reloadData];
 }
 
+#pragma mark - CPDFSignatureEditViewControllerDelegate
+
+- (void)signatureEditViewController:(CPDFSignatureEditViewController *)signatureEditViewController image:(UIImage *)image{
+    [[CSignatureManager sharedManager] addImageSignature:image];
+    [self.tableView reloadData];
+    
+//    CPDFSignatureAnnotation *annotation = [[CPDFSignatureAnnotation alloc] initWithDocument:self.annotManage.pdfListView.document];
+//    [annotation setImage:image];
+//    self.annotManage.pdfListView.addAnnotation = annotation;
+}
+
 @end

+ 1 - 13
compdfkit-tools/compdfkit-tools/Annotation/PDFProperties/PDFSignature/CSignatureDrawView.m

@@ -34,7 +34,7 @@ static NSInteger _index;
         self.bezierPath = [[UIBezierPath alloc] init];
         self.lineWidth = 1;
         
-        self.backgroundColor = [UIColor whiteColor];
+        self.backgroundColor = [UIColor clearColor];
     }
     return self;
 }
@@ -64,18 +64,6 @@ static NSInteger _index;
             }
         }
     }
-    
-    NSString *string = @"Sign here";
-    self.textRect = CGRectInset(rect, (rect.size.width/7)*2, (rect.size.height/7)*3);
-    UIFont *font = [UIFont systemFontOfSize:30];
-    NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:string attributes:@{NSFontAttributeName:font, NSForegroundColorAttributeName:[UIColor grayColor]}];
-    CGSize textSize = [attributedText boundingRectWithSize:rect.size options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) context:nil].size;
-
-    CGFloat x = self.textRect.origin.x + (self.textRect.size.width - textSize.width) / 2.0;
-    CGFloat y = self.textRect.origin.y + (self.textRect.size.height - textSize.height) / 2.0;
-    CGPoint center = CGPointMake(x, y);
-
-    [attributedText drawAtPoint:center];
 }
 
 #pragma mark - Draw Methods

+ 1 - 17
compdfkit-tools/compdfkit-tools/Common/Views/PDFAnnotationBar/CPDFAnnotationBar.m

@@ -575,11 +575,7 @@
 }
 
 - (void)signatureViewController:(CPDFSignatureViewController *)signatureViewController {
-    CPDFSignatureEditViewController *editVC = [[CPDFSignatureEditViewController alloc] init];
-    CNavigationController *nav = [[CNavigationController alloc]initWithRootViewController:editVC];
-    editVC.delegate = self;
-    
-    [self.parentVC presentViewController:nav animated:YES completion:nil];
+   
 }
 
 - (void)signatureViewController:(CPDFSignatureViewController *)signatureViewController image:(UIImage *)image {
@@ -589,18 +585,6 @@
     self.annotManage.pdfListView.addAnnotation = annotation;
 }
 
-#pragma mark - CPDFSignatureEditViewControllerDelegate
-
-- (void)signatureEditViewController:(CPDFSignatureEditViewController *)signatureEditViewController image:(UIImage *)image{
-    [[CSignatureManager sharedManager] addImageSignature:image];
-    [self reloadData];
-    [self.signatureVC.tableView reloadData];
-    
-    CPDFSignatureAnnotation *annotation = [[CPDFSignatureAnnotation alloc] initWithDocument:self.annotManage.pdfListView.document];
-    [annotation setImage:image];
-    self.annotManage.pdfListView.addAnnotation = annotation;
-}
-
 #pragma mark - CPDFNoteViewControllerDelegate
 
 - (void)noteViewController:(CPDFNoteViewController *)noteViewController annotSytle:(CAnnotStyle *)annotStyle {

+ 7 - 11
compdfkit-tools/compdfkit-tools/Common/Views/PDFProperties/CPDFAnnotationSampleView.m

@@ -244,20 +244,16 @@
             CGContextSetAlpha(context, self.opcity);
             UIFont *font = [UIFont fontWithName:self.fontName size:self.thickness];
             NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-            if (self.isBold && !(self.isItalic)) {
-                font = [UIFont boldSystemFontOfSize:self.thickness];
-            } else if (self.isItalic && !(self.isBold)) {
-                font = [UIFont italicSystemFontOfSize:self.thickness];
-                
-            } else if (self.isBold && self.isItalic) {
-                font = [UIFont boldSystemFontOfSize:self.thickness];
-                font = [UIFont italicSystemFontOfSize:self.thickness];
-            }
             if (!self.fillColor) {
                 self.fillColor = [UIColor whiteColor];
             }
-            [dic addEntriesFromDictionary:@{NSFontAttributeName:font, NSForegroundColorAttributeName:self.fillColor}];
-            [sampleStr drawInRect:self.arrowRect withAttributes:dic];
+            NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:sampleStr attributes:@{NSFontAttributeName:font, NSForegroundColorAttributeName:self.fillColor}];
+            CGSize textSize = [attributedText boundingRectWithSize:rect.size options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) context:nil].size;
+
+            CGFloat x = self.bounds.origin.x + (self.bounds.size.width - textSize.width) / 2.0;
+            CGFloat y = self.bounds.origin.y + (self.bounds.size.height - textSize.height) / 2.0;
+            CGPoint center = CGPointMake(x, y);
+            [attributedText drawAtPoint:center];
         }
             break;
         default:

+ 17 - 6
compdfkit-tools/compdfkit-tools/Common/Views/PDFProperties/CPDFFontStyleTableView.m

@@ -12,6 +12,8 @@
 
 #import "CPDFFontStyleTableView.h"
 
+#import <compdfkit_tools/CPDFColorUtils.h>
+
 @interface CPDFFontStyleTableView () <UITableViewDelegate, UITableViewDataSource>
 
 @property (nonatomic, strong) NSArray *dataArray;
@@ -22,6 +24,8 @@
 
 @property (nonatomic, strong) UITableView *tableView;
 
+@property (nonatomic, strong) UIView *headerView;
+
 @end
 
 @implementation CPDFFontStyleTableView
@@ -45,24 +49,31 @@
 
 - (instancetype)initWithFrame:(CGRect)frame {
     if (self = [super initWithFrame:frame]) {
-        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake((self.frame.size.width - 120)/2, 0, 120, (self.bounds.size.height - 40)/6)];
+        self.headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, 50)];
+        self.headerView.layer.borderColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1].CGColor;
+        self.headerView.layer.borderWidth = 1.0;
+        self.headerView.backgroundColor = [CPDFColorUtils CAnnotationPropertyViewControllerBackgoundColor];
+        [self addSubview:self.headerView];
+        
+        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake((self.frame.size.width - 120)/2, 0, 120, 50)];
         self.titleLabel.text = NSLocalizedString(@"Font Name", nil);
         self.titleLabel.autoresizingMask  = UIViewAutoresizingFlexibleHeight;
-        [self addSubview:self.titleLabel];
+        [self.headerView addSubview:self.titleLabel];
         
-        self.backBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 0, 40, (self.bounds.size.height - 40)/6)];
+        self.backBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 0, 40, 50)];
         self.backBtn.autoresizingMask = UIViewAutoresizingFlexibleHeight;
         [self.backBtn setImage:[UIImage imageNamed:@"CPDFAnnotationBarImageUndo" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
         [self.backBtn addTarget:self action:@selector(buttonItemClicked_back:) forControlEvents:UIControlEventTouchUpInside];
-        [self addSubview:self.backBtn];
+        [self.headerView addSubview:self.backBtn];
         
-        self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, (self.bounds.size.height - 40)/6, self.bounds.size.width, self.bounds.size.height) style:UITableViewStylePlain];
+        self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, self.bounds.size.width, self.bounds.size.height) style:UITableViewStylePlain];
         self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
         self.tableView.delegate = self;
         self.tableView.dataSource = self;
+        self.tableView.backgroundColor = [CPDFColorUtils CAnnotationSampleBackgoundColor];
         [self addSubview:self.tableView];
         
-        self.backgroundColor = [UIColor whiteColor];
+        self.backgroundColor =  self.backgroundColor = [CPDFColorUtils CAnnotationSampleBackgoundColor];;
     }
     return self;;
 }