fix: use readable guider to layout section header

This commit is contained in:
ihugo 2021-04-13 17:53:18 +08:00
parent 901176e14d
commit db3d16be41
3 changed files with 17 additions and 5 deletions

4
.gitignore vendored
View File

@ -120,4 +120,6 @@ xcuserdata
# End of https://www.toptal.com/developers/gitignore/api/swift,swiftpm,xcode,cocoapods
Localization/StringsConvertor/input
Localization/StringsConvertor/output
Localization/StringsConvertor/output
.DS_Store
/Mastodon.xcworkspace/xcshareddata/swiftpm

View File

@ -1161,8 +1161,8 @@
5B90C455262599800002E742 /* Settings */ = {
isa = PBXGroup;
children = (
5B90C456262599800002E742 /* SettingsViewModel.swift */,
5B90C457262599800002E742 /* View */,
5B90C456262599800002E742 /* SettingsViewModel.swift */,
5B90C45D262599800002E742 /* SettingsViewController.swift */,
);
path = Settings;

View File

@ -7,6 +7,11 @@
import UIKit
struct GroupedTableViewConstraints {
static let topMargin: CGFloat = 40
static let bottomMargin: CGFloat = 10
}
/// section header which supports add a custom view blelow the title
class SettingsSectionHeader: UIView {
lazy var titleLabel: UILabel = {
@ -21,7 +26,12 @@ class SettingsSectionHeader: UIView {
let view = UIStackView()
view.translatesAutoresizingMaskIntoConstraints = false
view.isLayoutMarginsRelativeArrangement = true
view.layoutMargins = UIEdgeInsets(top: 40, left: 12, bottom: 10, right: 12)
view.layoutMargins = UIEdgeInsets(
top: GroupedTableViewConstraints.topMargin,
left: 0,
bottom: GroupedTableViewConstraints.bottomMargin,
right: 0
)
view.axis = .vertical
return view
}()
@ -37,8 +47,8 @@ class SettingsSectionHeader: UIView {
addSubview(stackView)
NSLayoutConstraint.activate([
stackView.leadingAnchor.constraint(equalTo: self.leadingAnchor),
stackView.trailingAnchor.constraint(lessThanOrEqualTo: self.trailingAnchor),
stackView.leadingAnchor.constraint(equalTo: self.readableContentGuide.leadingAnchor),
stackView.trailingAnchor.constraint(lessThanOrEqualTo: self.readableContentGuide.trailingAnchor),
stackView.bottomAnchor.constraint(equalTo: self.bottomAnchor),
stackView.topAnchor.constraint(equalTo: self.topAnchor),
])