AutoLayout布局-文本列-去除尾部和前导警告
创始人
2024-09-23 07:01:04
0

如果在使用Auto Layout布局时显示了文本列中的尾部和前导警告,则可以按以下方式解决:

  1. 创建一个父级UIView,并添加约束。

  2. 在此UIView中创建两列文本。

  3. 为第一列文本添加以下约束:

a. 上部约束限制为父级UIView的上部。

b. 左侧约束限制为父级UIView的左侧。

c. 宽度约束限制为父级UIView的宽度的一半。

d. 底部约束限制为第二列文本的上部。

  1. 为第二列文本添加以下约束:

a. 上部约束限制为第一列文本的下部。

b. 右侧约束限制为父级UIView的右侧。

c. 宽度约束限制为父级UIView的宽度的一半。

d. 底部约束限制为父级UIView的底部。

这是一个示例代码:

let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = .lightGray
view.layer.cornerRadius = 5.0
self.view.addSubview(view)

NSLayoutConstraint.activate([
    view.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 20),
    view.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: 20),
    view.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: -20),
    view.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: -20)
])

let leftLabel = UILabel()
leftLabel.translatesAutoresizingMaskIntoConstraints = false
leftLabel.text = "Left Column"
leftLabel.numberOfLines = 0
leftLabel.backgroundColor = .white
leftLabel.layer.cornerRadius = 5.0
leftLabel.layer.borderColor = UIColor.black.cgColor
leftLabel.layer.borderWidth = 1.0
view.addSubview(leftLabel)

let rightLabel = UILabel()
rightLabel.translatesAutoresizingMaskIntoConstraints = false
rightLabel.text = "Right Column"
rightLabel.numberOfLines = 0
rightLabel.backgroundColor = .white
rightLabel.layer.cornerRadius = 5.0
rightLabel.layer.borderColor = UIColor.black.cgColor
rightLabel.layer.borderWidth = 1.0
view.addSubview(rightLabel)

NSLayoutConstraint.activate([
    leftLabel.topAnchor.constraint(equalTo: view.topAnchor, constant: 10),
    leftLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 10),
    leftLabel.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 0.5, constant: -15),
    leftLabel.bottomAnchor.constraint(equalTo: rightLabel.topAnchor, constant: -10),
    
    rightLabel.topAnchor.constraint

相关内容

热门资讯

记者揭秘!智星菠萝辅助(透视辅... 记者揭秘!智星菠萝辅助(透视辅助)拱趴大菠萝辅助神器,扑克教程(有挂细节);模式供您选择,了解更新找...
一分钟揭秘!约局吧能能开挂(透... 一分钟揭秘!约局吧能能开挂(透视辅助)hhpoker辅助靠谱,2024新版教程(有挂教学);约局吧能...
透视辅助!wepoker模拟器... 透视辅助!wepoker模拟器哪个好用(脚本)hhpoker辅助挂是真的,科技教程(有挂技巧);囊括...
透视代打!hhpkoer辅助器... 透视代打!hhpkoer辅助器视频(辅助挂)pokemmo脚本辅助,2024新版教程(有挂教程);风...
透视了解!约局吧德州真的有透视... 透视了解!约局吧德州真的有透视挂(透视脚本)德州局HHpoker透视脚本,必胜教程(有挂分析);亲,...
六分钟了解!wepoker挂底... 六分钟了解!wepoker挂底牌(透视)德普之星开辅助,详细教程(有挂解密);德普之星开辅助是一种具...
9分钟了解!wpk私人辅助(透... 9分钟了解!wpk私人辅助(透视)hhpoker德州透视,插件教程(有挂教学);风靡全球的特色经典游...
推荐一款!wepoker究竟有... 推荐一款!wepoker究竟有透视(脚本)哈糖大菠萝开挂,介绍教程(有挂技术);囊括全国各种wepo...
每日必备!wepoker有人用... 每日必备!wepoker有人用过(脚本)wpk有那种辅助,线上教程(有挂规律);wepoker有人用...
玩家必备教程!wejoker私... 玩家必备教程!wejoker私人辅助软件(脚本)哈糖大菠萝可以开挂,可靠技巧(有挂神器)申哈糖大菠萝...