Advertisement
Don_Mag

Untitled

Jul 2nd, 2023 (edited)
1,287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.21 KB | None | 0 0
  1. class LayoutTestVC: UIViewController {
  2.    
  3.     override func viewDidLoad() {
  4.         super.viewDidLoad()
  5.        
  6.         let testView = YourCustomView(frame: .init(x: 0, y: 0, width: 300, height: 160))
  7.     }
  8.    
  9. }
  10.  
  11. class ContentView: UIView {
  12. }
  13.  
  14. class YourCustomView: UIView {
  15.    
  16.     var contentView: ContentView!
  17.     let thumbWidth: CGFloat = 40.0
  18.    
  19.     override init(frame: CGRect) {
  20.         super.init(frame: frame)
  21.         setupContentView()
  22.     }
  23.     required init?(coder: NSCoder) {
  24.         super.init(coder: coder)
  25.         setupContentView()
  26.     }
  27.    
  28.     private func setupContentView() {
  29.         contentView = ContentView(frame: .zero)
  30.         contentView.translatesAutoresizingMaskIntoConstraints = false
  31.         addSubview(contentView)
  32.         contentView.leftAnchor.constraint(equalTo: leftAnchor, constant:thumbWidth).isActive = true
  33.         contentView.rightAnchor.constraint(equalTo: rightAnchor, constant: -thumbWidth).isActive = true
  34.         contentView.topAnchor.constraint(equalTo: topAnchor).isActive = true
  35.         contentView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
  36.         contentView.clipsToBounds = true
  37.         contentView.isUserInteractionEnabled = true
  38.         contentView.layoutIfNeeded()
  39.         NSLog("ContentView bounds \(contentView.bounds), view bounds \(self.bounds)")
  40.     }
  41.    
  42. }
  43.  
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement