如何在Swift中使用sizeThatFits?
我有一个文本视图和这样的视图
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
- parsing器错误错误域= NSXMLParserErrorDomain代码= 4“操作无法完成。”
- NSURLConnection:JSON文本没有以数组或对象和选项开始,以允许片段没有设置
- 按照存储为值的对象的属性sortingNSDictionary
- 如何自定义UIRefreshControl不同的图像和位置?
- 使用parsingjoin两个表
- Facebook的iOS SDK:为什么我得到“你必须升级这个应用程序graphicsAPI v2.x”?
- 多次购买会发生什么情况 – 非续约订阅应用内购买
- 阅读csv文件的ios
- iOS应用程序启动黑屏,UINavigationController,Nib,RootViewController