How to make UIView constraints layout , according to its drawRect method?

132 Views Asked by At

I want to use UIView to render String, instead of UILabel.

UILabel has fit intrinsic content size, for constraints auto layout .

Using UIView to render String, its dynamic height is zero when using auto layout.

        // auto layout using snapKit
        // customView's super view is a scrollView
        customView.snp.makeConstraints { (m) in
             m.top.leading.equalToSuperview()
             m.width.equalTo(200)
             m.bottom.equalToSuperview()
         }

I can give customView a fit rect, by calculating the string size, fill in the layout part code.

Just wonder whether there is an other convenient way to make UIView constraints layout according to its drawRect method

0

There are 0 best solutions below