作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有一个 TextView 和一个像这样的 View
let lb = UITextView()
let view = UIView()
background_img_view.addSubview(about_txt)
lb
没有固定的高度,可以是 30 或 300px,如何使用 sizeThatFits
来调整 background_img_view
的高度取决于 lb
的?
最佳答案
试试这个:
// Get the width you want to fit
let fixedWidth = textView.frame.size.width
// Calculate the biggest size that fixes in the given CGSize
let newSize = textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.greatestFiniteMagnitude))
// Set the textView's size to be whatever is bigger: The fitted width or the fixedWidth
textView.frame.size = CGSize(width: max(newSize.width, fixedWidth), height: newSize.height)
// Make the "background_img_view" height match the textView's height
background_img_view.frame.size.height = textView.frame.size.height
关于ios - 如何在 Swift 中使用 sizeThatFits?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42790079/
我是一名优秀的程序员,十分优秀!