Browse Source

VLCSectionTableHeader: Use custom label

Mike JS. Choi 7 years ago
parent
commit
05c3252759
2 changed files with 31 additions and 24 deletions
  1. 27 15
      Sources/VLCSectionTableHeaderView.swift
  2. 4 9
      Sources/VLCSettingsController.m

+ 27 - 15
Sources/VLCSectionTableHeaderView.swift

@@ -15,6 +15,21 @@ import Foundation
 class VLCSectionTableHeaderView: UITableViewHeaderFooterView {
 
     let separator = UIView()
+    
+    @objc let label: UILabel = {
+        let label = UILabel()
+        label.numberOfLines = 0
+        label.font = PresentationTheme.current.font.tableHeaderFont
+        return label
+    }()
+    
+    let stackView: UIStackView = {
+        let stackView = UIStackView()
+        stackView.spacing = 8
+        stackView.axis = .vertical
+        stackView.translatesAutoresizingMaskIntoConstraints = false
+        return stackView
+    }()
 
     override init(reuseIdentifier: String?) {
         super.init(reuseIdentifier: reuseIdentifier)
@@ -28,26 +43,23 @@ class VLCSectionTableHeaderView: UITableViewHeaderFooterView {
     }
 
     func setupUI() {
-        separator.translatesAutoresizingMaskIntoConstraints = false
-        contentView.addSubview(separator)
-
+        stackView.addArrangedSubview(separator)
+        stackView.addArrangedSubview(label)
+        contentView.addSubview(stackView)
+        
         NSLayoutConstraint.activate([
-            separator.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 20),
-            separator.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -20),
-            separator.heightAnchor.constraint(equalToConstant: 1),
-            separator.topAnchor.constraint(equalTo: contentView.topAnchor)
-            ])
+            stackView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 15),
+            stackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -15),
+            stackView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 15),
+            stackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -9),
+            
+            separator.heightAnchor.constraint(equalToConstant: 1)
+        ])
     }
 
     @objc func updateTheme() {
         contentView.backgroundColor = PresentationTheme.current.colors.background
         separator.backgroundColor = PresentationTheme.current.colors.separatorColor
-        textLabel?.textColor = PresentationTheme.current.colors.cellTextColor
-    }
-
-    override func layoutSubviews() {
-        super.layoutSubviews()
-        textLabel?.font = PresentationTheme.current.font.tableHeaderFont
-        textLabel?.textColor = PresentationTheme.current.colors.cellTextColor
+        label.textColor = PresentationTheme.current.colors.cellTextColor
     }
 }

+ 4 - 9
Sources/VLCSettingsController.m

@@ -18,7 +18,6 @@
 #import <LocalAuthentication/LocalAuthentication.h>
 #import "VLC_iOS-Swift.h"
 
-CGFloat const SETTINGS_HEADER_HEIGHT = 64.;
 NSString * const kVLCSectionTableHeaderViewIdentifier = @"VLCSectionTableHeaderViewIdentifier";
 
 @interface VLCSettingsController ()<PAPasscodeViewControllerDelegate>
@@ -59,16 +58,17 @@ NSString * const kVLCSectionTableHeaderViewIdentifier = @"VLCSectionTableHeaderV
     self.navigationItem.leftBarButtonItem.accessibilityIdentifier = VLCAccessibilityIdentifier.about;
 
     self.neverShowPrivacySettings = YES;
+    self.tableView.rowHeight = UITableViewAutomaticDimension;
     self.tableView.estimatedRowHeight = 100;
+    self.tableView.sectionHeaderHeight = UITableViewAutomaticDimension;
+    self.tableView.estimatedSectionHeaderHeight = 64;
     self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
-    self.tableView.rowHeight = UITableViewAutomaticDimension;
     [self.tableView registerClass:[VLCSectionTableHeaderView class] forHeaderFooterViewReuseIdentifier:kVLCSectionTableHeaderViewIdentifier];
     [self themeDidChange];
 }
 
 - (void)themeDidChange
 {
-
     self.view.backgroundColor = PresentationTheme.current.colors.background;
     [self setNeedsStatusBarAppearanceUpdate];
 }
@@ -194,18 +194,13 @@ NSString * const kVLCSectionTableHeaderViewIdentifier = @"VLCSectionTableHeaderV
 
 #pragma mark - InAppSettings customization
 
-- (CGFloat)settingsViewController:(id<IASKViewController>)settingsViewController tableView:(UITableView *)tableView heightForHeaderForSection:(NSInteger)section
-{
-    return section == 0. ? 0. : SETTINGS_HEADER_HEIGHT;
-}
-
 - (UIView *)settingsViewController:(id<IASKViewController>)settingsViewController tableView:(UITableView *)tableView viewForHeaderForSection:(NSInteger)section
 {
     if (section == 0) {
         return nil;
     }
     VLCSectionTableHeaderView *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:kVLCSectionTableHeaderViewIdentifier];
-    header.textLabel.text = [self.settingsReader titleForSection:section];
+    header.label.text = [self.settingsReader titleForSection:section];
     return header;
 }