Don_Mag icon

Untitled

Don_Mag | PRO | 07/02/23 01:56:23 PM UTC (Edited) | 0 ⭐ | 8080 👁️ | Never ⏰ | []
Swift |

1.21 KB

|

None

|

0 👍

/

0 👎

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

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎