swift - 基于 Swift 内容的动态 UITextView 大小

标签 swift ios8 uitextview

我不认为有人可以指导我以正确的方式动态调整 UITextView 的大小,同时仍然使用自动布局?也就是说,使用 Swift。

我已经尝试以编程方式调整底部约束,试图让 UITextView 包含内容。但是我不确定如何获取 UITextView 内容的高度?

我正在尝试将数据加载到 UITextView 字段中,然后动态调整它们以使其看起来整洁。

@IBOutlet weak var serviceDescriptionTextViewBottomGuide: NSLayoutConstraint! 

override func viewDidLoad() {

        self.activityName.text = serviceCodes[selectionValue]
        self.serviceDescriptionTextView.text = serviceDescription[selectionValue]
        self.whenToUseDescriptionTextView.text = whenToUseCode[selectionValue]

        self.serviceDescriptionTextViewBottomGuide?.constant += x
    }

enter image description here

最佳答案

禁用滚动并且不要设置任何其他可以决定 UITextView 高度的约束。

关于swift - 基于 Swift 内容的动态 UITextView 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29403241/

相关文章:

ios - 无法在 iOS 8 上选择联系人

ios - UITableView 背景色 Swift

ios - 有没有办法将 Touch ID 与 iOS Keychain 一起使用,但不提示输入用户密码?

ios - 无法使用 segue 将数组传递给第二个 View Controller

iOS 8 Today Widget - SLComposeViewController 显示不正确

ios - 在 UITextView 中选择一个词

ios - 如何同时检查 textField 和 textView 中的相同条件?

ios - 将文本设置为 uitextview 应用程序崩溃 - ios sdk

ios - iOS 中的 Xcode 类名不带应用程序名称前缀

ios - 不一致的快速行为