class LayoutTestVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let testView = YourCustomView(frame: .init(x: 0, y: 0, width: 300, height: 160))
}
}
class ContentView: UIView {
}
class YourCustomView: UIView {
var contentView: ContentView!
let thumbWidth: CGFloat = 40.0
override init(frame: CGRect) {
super.init(frame: frame)
setupContentView()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setupContentView()
}
private func setupContentView() {
contentView = ContentView(frame: .zero)
contentView.translatesAutoresizingMaskIntoConstraints = false
addSubview(contentView)
contentView.leftAnchor.constraint(equalTo: leftAnchor, constant:thumbWidth).isActive = true
contentView.rightAnchor.constraint(equalTo: rightAnchor, constant: -thumbWidth).isActive = true
contentView.topAnchor.constraint(equalTo: topAnchor).isActive = true
contentView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
contentView.clipsToBounds = true
contentView.isUserInteractionEnabled = true
contentView.layoutIfNeeded()
NSLog("ContentView bounds \(contentView.bounds), view bounds \(self.bounds)")
}
}
Comments
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎