具有额外填充的 UITableViewCell 内的 iOS Autolayout 2 多行 UILabel

标签 ios objective-c uitableview autolayout uilabel

我计划在 UITableViewCell 中并排使用两个宽度相等的 UILabel。不过,每个标签内的内容的长度是动态的,因此即使包含在同一表格单元格内,UILable 的高度也会不同。我在 XCode 6.0 下使用了自动布局。我能够通过自动布局约束实现一切,但唯一的障碍是 UILable 上存在的额外填充,如引用图像所示。我只是希望标签占据精确的尺寸,而不是像引用图像 enter image description here 中所示的附加填充。

以下是应用的约束:

enter image description here

最佳答案

每个标签上有两个垂直约束。现在考虑您需要标签顶部对齐的场景,您可以保持顶部约束不变。将 bottom constraint 更改为灵活的值,即 >=8。如果你想让它底部对齐,那么你需要放松top constraint

关于具有额外填充的 UITableViewCell 内的 iOS Autolayout 2 多行 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29210082/

相关文章:

ios - URLSession 委托(delegate)不适用于 swift 4.2

ios - 是否可以使用 Swift 创建自定义键盘而不强制用户通过设置屏幕附加它?

ios - TodayWidget 构建正确但 com.apple.springboard 正在运行

ios - 为什么我的 UIButton 图像大小在模拟器和设备中不同?

ios - 在 UITableview 中快速删除行并返回到上一个 View 时,应用程序崩溃

ios - 基于手机调整UIScrollView中UIView和UIButton之间的约束高度

使用 xCode 5.1.1 进行 iOS 编程

objective-c - 从基本 C、xcode 项目调用 Objective-C 类

ios - dequeueReusableHeaderFooterViewWithIdentifier 为单元格返回 nil,但 dequeueReusableCellWithIdentifier 不是

ios - 尝试在 tableView 中插入行时出现 NSInternalInconsistencyException