ios - UITextView 中的文本超出其框架 Swift 3

标签 ios swift user-interface uitextview programmatically

问题是当我在 textView 中输入一些文本时 文本超出其设定的框架。 不过,我正在以编程方式创建所有内容。

创建 UITextView:

    let descriptionTextView: UITextView = {
    let textView = UITextView()
    textView.backgroundColor = UIColor.customDarkGrayColor
    textView.text = "News Description"
    textView.textColor = UIColor.lightGray
    textView.font = UIFont.systemFont(ofSize: 15)
    textView.textContainerInset = UIEdgeInsets(top: 10, left: 16, bottom: 0, right: 16)
    textView.autocorrectionType = .no
    textView.setDefaultShadow()
    return textView
}()

使用我的自定义方法添加为 subview 并设置约束:

addSubview(descriptionTextView)

descriptionTextView.anchor(top: titleTextField.bottomAnchor, left: leftAnchor, bottom: nil, right: rightAnchor, paddingTop: 10, paddingLeft: 20, paddingBottom: 0, paddingRight: 20, width: 0, height: 80)

Check the bug here

最佳答案

关于在哪里查看的可能想法:

  • 您的 UITextView 目前是可滚动的,因此文本容器没有高度限制
  • 由于您添加了阴影,您可能将 masksToBoundsclipsToBounds 设置为 true,这就是文本出现在 View 框架之外的原因。

如果有帮助,请告诉我。干杯!

关于ios - UITextView 中的文本超出其框架 Swift 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46309671/

相关文章:

ios - 在 TableViewController Swift 中创建数组时未解析的标识符

swift - 枚举案例可以包含类列表吗?

ios - 在ios中设置自定义UI的大小

ios - 关于UIImageView定制的建议

css - 如何修改 StrongLoop 的 LoopBack Explorer CSS

ios - 检查 UITableViewCell 是否完全可见的最佳方法

ios - 从 UIView 发送按钮点击值到它的 super View 的 super View (UIViewController)-iOS

ios - RxSwift - 绑定(bind)到 tableView 的可选问题

ios - 当更改 Root View Controller 时,初始 View Controller 显示一秒或半秒

Python 3.5 - 将按钮放在按钮之上