diff --git a/CollapsibleTableSectionViewController.podspec b/CollapsibleTableSectionViewController.podspec index 552fd79..a426839 100644 --- a/CollapsibleTableSectionViewController.podspec +++ b/CollapsibleTableSectionViewController.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| # s.name = "CollapsibleTableSectionViewController" - s.version = "0.0.7" + s.version = "0.0.8" s.summary = "Swift 3.0 library to support collapsible sections in a table view." # This description is used to generate tags and improve search results. diff --git a/CollapsibleTableSectionViewController/CollapsibleTableViewHeader.swift b/CollapsibleTableSectionViewController/CollapsibleTableViewHeader.swift index 3a17631..43bf196 100644 --- a/CollapsibleTableSectionViewController/CollapsibleTableViewHeader.swift +++ b/CollapsibleTableSectionViewController/CollapsibleTableViewHeader.swift @@ -23,16 +23,29 @@ class CollapsibleTableViewHeader: UITableViewHeaderFooterView { override init(reuseIdentifier: String?) { super.init(reuseIdentifier: reuseIdentifier) - // - // Constraint the size of arrow label for auto layout - // - arrowLabel.widthAnchor.constraint(equalToConstant: 12).isActive = true + // Content View + contentView.backgroundColor = UIColor(hex: 0x2E3944) - titleLabel.translatesAutoresizingMaskIntoConstraints = false + + let marginGuide = contentView.layoutMarginsGuide + + // Arrow label + contentView.addSubview(arrowLabel) + arrowLabel.textColor = UIColor.white arrowLabel.translatesAutoresizingMaskIntoConstraints = false + arrowLabel.widthAnchor.constraint(equalToConstant: 12).isActive = true + arrowLabel.topAnchor.constraint(equalTo: marginGuide.topAnchor).isActive = true + arrowLabel.trailingAnchor.constraint(equalTo: marginGuide.trailingAnchor).isActive = true + arrowLabel.bottomAnchor.constraint(equalTo: marginGuide.bottomAnchor).isActive = true + // Title label contentView.addSubview(titleLabel) - contentView.addSubview(arrowLabel) + titleLabel.textColor = UIColor.white + titleLabel.translatesAutoresizingMaskIntoConstraints = false + titleLabel.topAnchor.constraint(equalTo: marginGuide.topAnchor).isActive = true + titleLabel.trailingAnchor.constraint(equalTo: marginGuide.trailingAnchor).isActive = true + titleLabel.bottomAnchor.constraint(equalTo: marginGuide.bottomAnchor).isActive = true + titleLabel.leadingAnchor.constraint(equalTo: marginGuide.leadingAnchor).isActive = true // // Call tapHeader when tapping on this header @@ -44,44 +57,6 @@ class CollapsibleTableViewHeader: UITableViewHeaderFooterView { fatalError("init(coder:) has not been implemented") } - override func layoutSubviews() { - super.layoutSubviews() - - contentView.backgroundColor = UIColor(hex: 0x2E3944) - - titleLabel.textColor = UIColor.white - arrowLabel.textColor = UIColor.white - - // - // Autolayout the lables - // - let views = [ - "titleLabel" : titleLabel, - "arrowLabel" : arrowLabel, - ] - - contentView.addConstraints(NSLayoutConstraint.constraints( - withVisualFormat: "H:|-20-[titleLabel]-[arrowLabel]-20-|", - options: [], - metrics: nil, - views: views - )) - - contentView.addConstraints(NSLayoutConstraint.constraints( - withVisualFormat: "V:|-[titleLabel]-|", - options: [], - metrics: nil, - views: views - )) - - contentView.addConstraints(NSLayoutConstraint.constraints( - withVisualFormat: "V:|-[arrowLabel]-|", - options: [], - metrics: nil, - views: views - )) - } - // // Trigger toggle section when tapping on the header // diff --git a/Examples/Examples.xcodeproj/project.pbxproj b/Examples/Examples.xcodeproj/project.pbxproj index 3797034..a96c046 100644 --- a/Examples/Examples.xcodeproj/project.pbxproj +++ b/Examples/Examples.xcodeproj/project.pbxproj @@ -9,7 +9,6 @@ /* Begin PBXBuildFile section */ 0AC886DF1F226627007E4E2F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AC886DE1F226627007E4E2F /* AppDelegate.swift */; }; 0AC886E11F226627007E4E2F /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AC886E01F226627007E4E2F /* ViewController.swift */; }; - 0AC886E41F226627007E4E2F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0AC886E21F226627007E4E2F /* Main.storyboard */; }; 0AC886E61F226627007E4E2F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0AC886E51F226627007E4E2F /* Assets.xcassets */; }; 0AC886E91F226627007E4E2F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0AC886E71F226627007E4E2F /* LaunchScreen.storyboard */; }; 1954D61128E2AEA6960297AB /* Pods_Examples.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 540185A9FAB3B385AE8ED8A6 /* Pods_Examples.framework */; }; @@ -19,7 +18,6 @@ 0AC886DB1F226627007E4E2F /* Examples.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Examples.app; sourceTree = BUILT_PRODUCTS_DIR; }; 0AC886DE1F226627007E4E2F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 0AC886E01F226627007E4E2F /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; - 0AC886E31F226627007E4E2F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 0AC886E51F226627007E4E2F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 0AC886E81F226627007E4E2F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 0AC886EA1F226627007E4E2F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -63,7 +61,6 @@ children = ( 0AC886DE1F226627007E4E2F /* AppDelegate.swift */, 0AC886E01F226627007E4E2F /* ViewController.swift */, - 0AC886E21F226627007E4E2F /* Main.storyboard */, 0AC886E51F226627007E4E2F /* Assets.xcassets */, 0AC886E71F226627007E4E2F /* LaunchScreen.storyboard */, 0AC886EA1F226627007E4E2F /* Info.plist */, @@ -153,7 +150,6 @@ files = ( 0AC886E91F226627007E4E2F /* LaunchScreen.storyboard in Resources */, 0AC886E61F226627007E4E2F /* Assets.xcassets in Resources */, - 0AC886E41F226627007E4E2F /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -220,14 +216,6 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ - 0AC886E21F226627007E4E2F /* Main.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 0AC886E31F226627007E4E2F /* Base */, - ); - name = Main.storyboard; - sourceTree = ""; - }; 0AC886E71F226627007E4E2F /* LaunchScreen.storyboard */ = { isa = PBXVariantGroup; children = ( diff --git a/Examples/Examples/AppDelegate.swift b/Examples/Examples/AppDelegate.swift index a22f926..03aa687 100644 --- a/Examples/Examples/AppDelegate.swift +++ b/Examples/Examples/AppDelegate.swift @@ -13,34 +13,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. + self.window = UIWindow(frame:UIScreen.main.bounds) + self.window?.backgroundColor = UIColor.white + self.window?.rootViewController = UINavigationController(rootViewController: ViewController()) + self.window?.makeKeyAndVisible() + return true } - func applicationWillResignActive(_ application: UIApplication) { - // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. - } - - func applicationDidEnterBackground(_ application: UIApplication) { - // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. - // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. - } - - func applicationWillEnterForeground(_ application: UIApplication) { - // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. - } - - func applicationDidBecomeActive(_ application: UIApplication) { - // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. - } - - func applicationWillTerminate(_ application: UIApplication) { - // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. - } - - } diff --git a/Examples/Examples/Base.lproj/Main.storyboard b/Examples/Examples/Base.lproj/Main.storyboard deleted file mode 100644 index 4d1eaa8..0000000 --- a/Examples/Examples/Base.lproj/Main.storyboard +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Examples/Examples/Info.plist b/Examples/Examples/Info.plist index d052473..c12df3b 100644 --- a/Examples/Examples/Info.plist +++ b/Examples/Examples/Info.plist @@ -22,8 +22,6 @@ UILaunchStoryboardName LaunchScreen - UIMainStoryboardFile - Main UIRequiredDeviceCapabilities armv7 diff --git a/Examples/Examples/ViewController.swift b/Examples/Examples/ViewController.swift index a10dfec..e600e29 100644 --- a/Examples/Examples/ViewController.swift +++ b/Examples/Examples/ViewController.swift @@ -9,18 +9,14 @@ import UIKit import CollapsibleTableSectionViewController -class ViewController: UIViewController { - - var sections = [Section]() +class ViewController: CollapsibleTableSectionViewController { override func viewDidLoad() { super.viewDidLoad() self.title = "Apple Products" - let controller: CollapsibleTableSectionViewController = CollapsibleTableSectionViewController() - - controller.sections = [ + self.sections = [ Section(name: "Mac", items: [ Item(name: "MacBook", detail: "Apple's ultraportable laptop, trading portability for speed and connectivity."), Item(name: "MacBook Air", detail: "While the screen could be sharper, the updated 11-inch MacBook Air is a very light ultraportable that offers great performance and battery life for the price."), @@ -44,15 +40,6 @@ class ViewController: UIViewController { Item(name: "Accessories", detail: "") ]) ] - - let tableView: UITableView = controller.tableView - - var frame = self.view.bounds - frame.origin.y = (navigationController?.navigationBar.frame.maxY)! - - tableView.frame = frame - - view.addSubview(tableView) } }