diff --git a/Examples/iOS Example/Sources/HeaderFooterSection.swift b/Examples/iOS Example/Sources/HeaderFooterSection.swift index dda28e64..17252942 100644 --- a/Examples/iOS Example/Sources/HeaderFooterSection.swift +++ b/Examples/iOS Example/Sources/HeaderFooterSection.swift @@ -4,12 +4,14 @@ import UIKit class HeaderFooterSection: UITableViewHeaderFooterView { + private let numberOflinesCornerRadius = 10 + lazy var titleLabel: UILabel = { let label = UILabel() label.text = " " label.isSkeletonable = true - label.linesCornerRadius = 10 + label.linesCornerRadius = numberOflinesCornerRadius return label }() diff --git a/Examples/iOS Example/Sources/UITextViewByCodeViewController.swift b/Examples/iOS Example/Sources/UITextViewByCodeViewController.swift index 139526b2..f91779ae 100644 --- a/Examples/iOS Example/Sources/UITextViewByCodeViewController.swift +++ b/Examples/iOS Example/Sources/UITextViewByCodeViewController.swift @@ -4,11 +4,18 @@ import UIKit import SkeletonView class UITextViewByCodeViewController: UIViewController { + + private let numberOflinesCornerRadius = 10 + private let topAnchorConstraintConst: CGFloat = 10 + private let leftAnchorConstraintConst: CGFloat = 10 + private let rightAnchorConstraintConst: CGFloat = -10 + private let heightAnchorConstraintConst: CGFloat = 100 + lazy var textView: UITextView = { let tv = UITextView() tv.text = " " - tv.linesCornerRadius = 10 + tv.linesCornerRadius = numberOflinesCornerRadius tv.isSkeletonable = true tv.translatesAutoresizingMaskIntoConstraints = false @@ -32,10 +39,10 @@ class UITextViewByCodeViewController: UIViewController { } func setupElementsConstraints() { - textView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor, constant: 10).isActive = true - textView.leftAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.leftAnchor, constant: 10).isActive = true - textView.rightAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.rightAnchor, constant: -10).isActive = true - textView.heightAnchor.constraint(equalToConstant: 100).isActive = true + textView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor, constant: topAnchorConstraintConst).isActive = true + textView.leftAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.leftAnchor, constant: leftAnchorConstraintConst).isActive = true + textView.rightAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.rightAnchor, constant: rightAnchorConstraintConst).isActive = true + textView.heightAnchor.constraint(equalToConstant: heightAnchorConstraintConst).isActive = true } func showSkeletonForElements() { diff --git a/Examples/iOS Example/Sources/ViewController.swift b/Examples/iOS Example/Sources/ViewController.swift index cb80e51c..11441b5d 100644 --- a/Examples/iOS Example/Sources/ViewController.swift +++ b/Examples/iOS Example/Sources/ViewController.swift @@ -10,27 +10,41 @@ import UIKit import SkeletonView class ViewController: UIViewController { + + // MARK: - Constants + + private let estimatedRowHeight = 120.0 + private let estimatedSectionFooterHeight = 20.0 + private let estimatedSectionHeaderHeight = 20.0 + + struct AccessibilityIdentifier { + static let tableViewHeaderIdentifier = "HeaderIdentifier" + static let tableViewFooterIdentifier = "FooterIdentifier" + } + + // MARK: - IBOutlet + @IBOutlet weak var tableview: UITableView! { didSet { tableview.rowHeight = UITableView.automaticDimension tableview.sectionHeaderHeight = UITableView.automaticDimension tableview.sectionFooterHeight = UITableView.automaticDimension - tableview.estimatedRowHeight = 120.0 - tableview.estimatedSectionFooterHeight = 20.0 - tableview.estimatedSectionHeaderHeight = 20.0 - tableview.register(HeaderFooterSection.self, forHeaderFooterViewReuseIdentifier: "HeaderIdentifier") - tableview.register(HeaderFooterSection.self, forHeaderFooterViewReuseIdentifier: "FooterIdentifier") + tableview.estimatedRowHeight = self.estimatedRowHeight + tableview.estimatedSectionFooterHeight = self.estimatedSectionFooterHeight + tableview.estimatedSectionHeaderHeight = estimatedSectionHeaderHeight + tableview.register(HeaderFooterSection.self, forHeaderFooterViewReuseIdentifier: AccessibilityIdentifier.tableViewHeaderIdentifier) + tableview.register(HeaderFooterSection.self, forHeaderFooterViewReuseIdentifier: AccessibilityIdentifier.tableViewFooterIdentifier) } } - @IBOutlet weak var avatarImage: UIImageView! { + @IBOutlet private weak var avatarImage: UIImageView! { didSet { avatarImage.layer.cornerRadius = avatarImage.frame.width/2 avatarImage.layer.masksToBounds = true - } + } } - @IBOutlet weak var colorSelectedView: UIView! { + @IBOutlet private weak var colorSelectedView: UIView! { didSet { colorSelectedView.layer.cornerRadius = 5 colorSelectedView.layer.masksToBounds = true @@ -38,16 +52,19 @@ class ViewController: UIViewController { } } - @IBOutlet weak var switchAnimated: UISwitch! - @IBOutlet weak var skeletonTypeSelector: UISegmentedControl! - @IBOutlet weak var showOrHideSkeletonButton: UIButton! - @IBOutlet weak var transitionDurationLabel: UILabel! - @IBOutlet weak var transitionDurationStepper: UIStepper! + @IBOutlet private weak var switchAnimated: UISwitch! + @IBOutlet private weak var skeletonTypeSelector: UISegmentedControl! + @IBOutlet private weak var showOrHideSkeletonButton: UIButton! + @IBOutlet private weak var transitionDurationLabel: UILabel! + @IBOutlet private weak var transitionDurationStepper: UIStepper! var type: SkeletonType { return skeletonTypeSelector.selectedSegmentIndex == 0 ? .solid : .gradient } + + // MARK: - Life Cycle + override func viewDidLoad() { super.viewDidLoad() tableview.isSkeletonable = true @@ -155,6 +172,8 @@ class ViewController: UIViewController { } } +// MARK: - Extensions + extension ViewController: UIPickerViewDelegate, UIPickerViewDataSource { func numberOfComponents(in pickerView: UIPickerView) -> Int { return 1