1
0
mirror of https://github.com/mastodon/mastodon-ios.git synced 2024-12-15 18:29:36 +01:00
mastodon-app-ufficiale-ipho.../MastodonSDK/Sources/MastodonUI/View/Container/AdaptiveMarginContainerView.swift
2022-02-18 17:49:20 +08:00

56 lines
1.6 KiB
Swift

//
// AdaptiveMarginContainerView.swift
//
//
// Created by MainasuK on 2022-2-18.
//
import UIKit
public final class AdaptiveMarginContainerView: UIView {
public var margin: CGFloat = 0 {
didSet { updateConstraints() }
}
public var contentView: UIView? {
didSet {
guard let contentView = contentView else { return }
guard contentView.superview == nil else { return }
contentView.translatesAutoresizingMaskIntoConstraints = false
addSubview(contentView)
let _leadingLayoutConstraint = contentView.leadingAnchor.constraint(equalTo: leadingAnchor)
let _trailingLayoutConstraint = trailingAnchor.constraint(equalTo: contentView.trailingAnchor)
NSLayoutConstraint.activate([
contentView.topAnchor.constraint(equalTo: topAnchor),
_leadingLayoutConstraint,
_trailingLayoutConstraint,
contentView.bottomAnchor.constraint(equalTo: bottomAnchor),
])
leadingLayoutConstraint = _leadingLayoutConstraint
trailingLayoutConstraint = _trailingLayoutConstraint
updateConstraints()
}
}
var leadingLayoutConstraint: NSLayoutConstraint?
var trailingLayoutConstraint: NSLayoutConstraint?
}
extension AdaptiveMarginContainerView {
public override func updateConstraints() {
super.updateConstraints()
leadingLayoutConstraint?.constant = margin
trailingLayoutConstraint?.constant = margin
}
}