You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Swift/UIKit中为何无法在界面上看到bioTextView?

问题解决:UIKit中UITextView文本无法显示

你的bioTextView看不到文本的核心原因是未设置宽度和高度约束。当前仅绑定了顶部和水平居中约束,Auto Layout无法推断出视图尺寸,最终导致视图被压缩为0大小,自然看不到文本和背景色。

修复方案

修改SetupConstraints方法中bioTextView的约束,补充宽度和高度相关规则,比如适配屏幕宽度的布局:

NSLayoutConstraint.activate([
    bioTextView.topAnchor.constraint(equalTo: followBtn.bottomAnchor, constant: 40),
    bioTextView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
    bioTextView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20),
    bioTextView.heightAnchor.constraint(greaterThanOrEqualToConstant: 100)
])

说明

  • 通过leadingAnchor和trailingAnchor绑定屏幕左右边缘(保留20pt内边距),确保在不同尺寸设备上自动适配宽度;
  • greaterThanOrEqualToConstant:100设置最小高度为100pt,当文本内容超过该高度时,UITextView会自动开启滚动,避免内容被截断。

修改后重新运行即可看到bioTextView的蓝色背景和黑色文本。

内容的提问来源于stack exchange,提问作者James

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 11:37:39