Prevent label from overflowing into below cell when using editing controls
This commit is contained in:
parent
2fead1f87d
commit
2a39ada5ab
|
@ -87,6 +87,7 @@ class MasterFeedTableViewCell : VibrantTableViewCell {
|
||||||
label.numberOfLines = 0
|
label.numberOfLines = 0
|
||||||
label.allowsDefaultTighteningForTruncation = false
|
label.allowsDefaultTighteningForTruncation = false
|
||||||
label.adjustsFontForContentSizeCategory = true
|
label.adjustsFontForContentSizeCategory = true
|
||||||
|
label.lineBreakMode = .byTruncatingTail
|
||||||
label.font = .preferredFont(forTextStyle: .body)
|
label.font = .preferredFont(forTextStyle: .body)
|
||||||
return label
|
return label
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -37,10 +37,6 @@ struct MasterFeedTableViewCellLayout {
|
||||||
if indent {
|
if indent {
|
||||||
initialIndent += MasterFeedTableViewCellLayout.disclosureButtonSize.width
|
initialIndent += MasterFeedTableViewCellLayout.disclosureButtonSize.width
|
||||||
}
|
}
|
||||||
if showingEditingControl {
|
|
||||||
initialIndent += MasterFeedTableViewCellLayout.editingControlIndent
|
|
||||||
}
|
|
||||||
|
|
||||||
let bounds = CGRect(x: initialIndent, y: 0.0, width: floor(cellWidth - initialIndent - insets.right), height: 0.0)
|
let bounds = CGRect(x: initialIndent, y: 0.0, width: floor(cellWidth - initialIndent - insets.right), height: 0.0)
|
||||||
|
|
||||||
// Disclosure Button
|
// Disclosure Button
|
||||||
|
@ -68,18 +64,12 @@ struct MasterFeedTableViewCellLayout {
|
||||||
if !unreadCountIsHidden {
|
if !unreadCountIsHidden {
|
||||||
rUnread.size = unreadCountSize
|
rUnread.size = unreadCountSize
|
||||||
rUnread.origin.x = bounds.maxX - (MasterFeedTableViewCellLayout.unreadCountMarginRight + unreadCountSize.width)
|
rUnread.origin.x = bounds.maxX - (MasterFeedTableViewCellLayout.unreadCountMarginRight + unreadCountSize.width)
|
||||||
if showingEditingControl {
|
|
||||||
rUnread.origin.x = rUnread.origin.x - MasterFeedTableViewCellLayout.editingControlIndent
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Title
|
// Title
|
||||||
|
var rLabelx = insets.left + MasterFeedTableViewCellLayout.disclosureButtonSize.width
|
||||||
var rLabelx = CGFloat.zero
|
if !shouldShowDisclosure {
|
||||||
if shouldShowDisclosure {
|
rLabelx = rLabelx + MasterFeedTableViewCellLayout.imageSize.width + MasterFeedTableViewCellLayout.imageMarginRight
|
||||||
rLabelx = bounds.minX + MasterFeedTableViewCellLayout.disclosureButtonSize.width
|
|
||||||
} else {
|
|
||||||
rLabelx = rFavicon.maxX + MasterFeedTableViewCellLayout.imageMarginRight
|
|
||||||
}
|
}
|
||||||
let rLabely = UIFontMetrics.default.scaledValue(for: MasterFeedTableViewCellLayout.verticalPadding)
|
let rLabely = UIFontMetrics.default.scaledValue(for: MasterFeedTableViewCellLayout.verticalPadding)
|
||||||
|
|
||||||
|
@ -91,7 +81,23 @@ struct MasterFeedTableViewCellLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
let labelSizeInfo = MultilineUILabelSizer.size(for: label.text ?? "", font: label.font, numberOfLines: 0, width: Int(floor(labelWidth)))
|
let labelSizeInfo = MultilineUILabelSizer.size(for: label.text ?? "", font: label.font, numberOfLines: 0, width: Int(floor(labelWidth)))
|
||||||
let rLabel = CGRect(x: rLabelx, y: rLabely, width: labelSizeInfo.size.width, height: labelSizeInfo.size.height)
|
|
||||||
|
// Now that we've got everything (especially the label) computed without the editing controls, update for them.
|
||||||
|
// We do this because we don't want the row height to change when the editing controls are brought out. We will
|
||||||
|
// handle the missing space, but removing it from the label and truncating.
|
||||||
|
if showingEditingControl {
|
||||||
|
rDisclosure.origin.x += MasterFeedTableViewCellLayout.editingControlIndent
|
||||||
|
rFavicon.origin.x += MasterFeedTableViewCellLayout.editingControlIndent
|
||||||
|
rLabelx += MasterFeedTableViewCellLayout.editingControlIndent
|
||||||
|
if !unreadCountIsHidden {
|
||||||
|
rUnread.origin.x -= MasterFeedTableViewCellLayout.editingControlIndent
|
||||||
|
labelWidth = cellWidth - (rLabelx + MasterFeedTableViewCellLayout.labelMarginRight + (cellWidth - rUnread.minX))
|
||||||
|
} else {
|
||||||
|
labelWidth = cellWidth - (rLabelx + MasterFeedTableViewCellLayout.labelMarginRight + MasterFeedTableViewCellLayout.editingControlIndent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let rLabel = CGRect(x: rLabelx, y: rLabely, width: labelWidth, height: labelSizeInfo.size.height)
|
||||||
|
|
||||||
// Determine cell height
|
// Determine cell height
|
||||||
let paddedLabelHeight = rLabel.maxY + UIFontMetrics.default.scaledValue(for: MasterFeedTableViewCellLayout.verticalPadding)
|
let paddedLabelHeight = rLabel.maxY + UIFontMetrics.default.scaledValue(for: MasterFeedTableViewCellLayout.verticalPadding)
|
||||||
|
|
Loading…
Reference in New Issue