Преглед изворни кода

PDFTools(iOS) - 暗黑模式适配

chenyu пре 1 година
родитељ
комит
2642a7afc0

+ 12 - 2
compdfkit-tools/compdfkit-tools/PDFInfo/CPDFInfoTableCell.m

@@ -19,19 +19,25 @@ NSString* kDocumentInfoValue = @"kDocumentInfoValue";
 - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)identifier
 {
     self = [super initWithStyle:style reuseIdentifier:identifier];
-    if (self) {
+    if (self)
+    {
         
         titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
         titleLabel.backgroundColor = [UIColor clearColor];
         titleLabel.opaque = NO;
+        titleLabel.textColor = [UIColor lightGrayColor];
+        titleLabel.highlightedTextColor = [UIColor lightGrayColor];
         titleLabel.font = [UIFont boldSystemFontOfSize:12];
         titleLabel.numberOfLines = 2;
         titleLabel.textAlignment = NSTextAlignmentRight;
         [self.contentView addSubview:titleLabel];
         
+        
         infoLabel = [[UILabel alloc] initWithFrame:CGRectZero];
         infoLabel.backgroundColor = [UIColor clearColor];
         infoLabel.opaque = NO;
+        infoLabel.textColor = [UIColor lightGrayColor];
+        infoLabel.highlightedTextColor = [UIColor lightGrayColor];
         infoLabel.font = [UIFont boldSystemFontOfSize:12];
         infoLabel.numberOfLines = 2;
         infoLabel.textAlignment = NSTextAlignmentLeft;
@@ -45,6 +51,8 @@ NSString* kDocumentInfoValue = @"kDocumentInfoValue";
     return self;
 }
 
+
+
 - (void)layoutSubviews
 {
     [super layoutSubviews];
@@ -65,11 +73,13 @@ NSString* kDocumentInfoValue = @"kDocumentInfoValue";
     [super setSelected:selected animated:animated];
 }
 
+
 - (void)setDataDictionary:(NSMutableDictionary *)newDictionary
 {
+    
     titleLabel.text = [newDictionary objectForKey:kDocumentInfoTitle];
     infoLabel.text = [newDictionary objectForKey:kDocumentInfoValue];
-        
+    
     [self setNeedsLayout];
 }
 

+ 24 - 5
compdfkit-tools/compdfkit-tools/PDFInfo/CPDFInfoViewController.m

@@ -33,11 +33,23 @@
 - (void)viewDidLoad
 {
     [super viewDidLoad];
-    
+    if (@available(iOS 12.0, *)) {
+        BOOL isDark = (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark);
+        if(isDark){
+            self.view.backgroundColor = [UIColor blackColor];
+        }else{
+            self.view.backgroundColor = [UIColor colorWithRed:240/255. green:240/255. blue:240/255. alpha:1.];
+        }
+    } else {
+        // Fallback on earlier versions
+        self.view.backgroundColor = [UIColor colorWithRed:240/255. green:240/255. blue:240/255. alpha:1.];
+    }
+
     self.title = NSLocalizedString(@"File Info",nil);
     [self loadDocumentInfo];
     
     [self.view addSubview:self.curTableView];
+    
 }
 
 - (void)viewWillAppear:(BOOL)animated
@@ -47,6 +59,13 @@
     [self updateInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation]];
 }
 
+-(void)viewWillDisappear:(BOOL)animated
+{
+    [super viewWillDisappear:animated];
+    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
+    }
+}
+
 - (void)updateInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
 {
     int inset = 0;
@@ -57,17 +76,19 @@
 #pragma mark - getter && setter
 
 - (UITableView*) curTableView {
+    
     if (!_curTableView) {
         _curTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
         _curTableView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
         _curTableView.delegate = self;
         _curTableView.dataSource = self;
         _curTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
-        _curTableView.tableFooterView = [[UIView alloc] init];
+        _curTableView.backgroundColor = [UIColor clearColor];
     }
     return _curTableView;
 }
 
+
 #pragma mark - private method
 
 - (NSString *)fileSizeStr {
@@ -150,6 +171,7 @@
         }
     }
     
+    
     if (documentAttributes[CPDFDocumentModificationDateAttribute]){
         NSMutableString* mSting = [NSMutableString string];
         NSString*    tstring = [NSString stringWithFormat:@"%@",documentAttributes[CPDFDocumentModificationDateAttribute]];
@@ -234,9 +256,6 @@
     return 35;
 }
 
-- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
-    return 30.0;
-}
 
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {

+ 10 - 7
compdfkit-tools/compdfkit-tools/PDFPageTurning/CPDFPageTurnView.m

@@ -51,8 +51,10 @@
     switch (self.atPosition) {
         case CPDFPageTurnViewPositionLeftBottom: {
             if (@available(iOS 11.0, *)) {
-                offsetX += [UIApplication sharedApplication].windows.firstObject.safeAreaInsets.left;
-                offsetY += [UIApplication sharedApplication].windows.firstObject.safeAreaInsets.top;
+                if(TARGET_OS_IPHONE){
+                    offsetX += [UIApplication sharedApplication].windows.firstObject.safeAreaInsets.left;
+                    offsetY += [UIApplication sharedApplication].windows.firstObject.safeAreaInsets.top;
+                }
             }
             offsetY = self.superview.frame.size.height - offsetY;
         }
@@ -61,13 +63,12 @@
         default:
             break;
     }
-    
-    if(TARGET_OS_IPHONE){
+    if(UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad){
         if ([UIApplication sharedApplication].statusBarOrientation == UIDeviceOrientationPortrait ||
         [UIApplication sharedApplication].statusBarOrientation == UIDeviceOrientationPortraitUpsideDown) {
             offsetY +=20;
         } else {
-            offsetX -= 40;
+            offsetX -= 50;
             offsetY -= 20;
         }
     }
@@ -75,6 +76,7 @@
     self.frame = CGRectMake(offsetX, offsetY, self.pageNumButton.frame.size.width, self.pageNumButton.frame.size.height);
 }
 
+
 #pragma mark - Public method
 
 - (void)showInView:(UIView *)subView position:(CPDFPageTurnViewPosition)position {
@@ -88,8 +90,9 @@
 - (void)updatePageCount:(NSUInteger)pageCount currentPageIndex:(NSUInteger)currentPageIndex {
     
     [self.pageNumButton setTitle:[NSString stringWithFormat:@" %ld/%ld ",currentPageIndex,pageCount] forState:UIControlStateNormal];
+    self.pageNumButton.titleLabel.font = [UIFont systemFontOfSize:12.f];
     [self.pageNumButton sizeToFit];
-    self.pageNumButton.frame = CGRectMake(self.pageNumButton.frame.origin.x, self.pageNumButton.frame.origin.y, self.pageNumButton.frame.size.width + 30, self.pageNumButton.frame.size.height);
+    self.pageNumButton.frame = CGRectMake(self.pageNumButton.frame.origin.x, self.pageNumButton.frame.origin.y, self.pageNumButton.frame.size.width + 10, self.pageNumButton.frame.size.height);
 
     self.pageNumButton.backgroundColor = self.indicatorBackgroudColor;
     self.pageNumButton.layer.cornerRadius = self.indicatorCornerRadius;
@@ -107,7 +110,7 @@
 #pragma mark - Private method
 
 - (CGFloat)pageOffset {
-    return 30;
+    return 40;
 }