Make attributed titles work on iOS
This commit is contained in:
parent
cce4b56ee5
commit
070981553d
|
@ -12,6 +12,7 @@ import Articles
|
||||||
struct MasterTimelineCellData {
|
struct MasterTimelineCellData {
|
||||||
|
|
||||||
let title: String
|
let title: String
|
||||||
|
let attributedTitle: NSAttributedString
|
||||||
let summary: String
|
let summary: String
|
||||||
let dateString: String
|
let dateString: String
|
||||||
let feedName: String
|
let feedName: String
|
||||||
|
@ -28,6 +29,7 @@ struct MasterTimelineCellData {
|
||||||
init(article: Article, showFeedName: ShowFeedName, feedName: String?, byline: String?, iconImage: IconImage?, showIcon: Bool, featuredImage: UIImage?, numberOfLines: Int, iconSize: IconSize) {
|
init(article: Article, showFeedName: ShowFeedName, feedName: String?, byline: String?, iconImage: IconImage?, showIcon: Bool, featuredImage: UIImage?, numberOfLines: Int, iconSize: IconSize) {
|
||||||
|
|
||||||
self.title = ArticleStringFormatter.truncatedTitle(article)
|
self.title = ArticleStringFormatter.truncatedTitle(article)
|
||||||
|
self.attributedTitle = ArticleStringFormatter.attributedTruncatedTitle(article)
|
||||||
self.summary = ArticleStringFormatter.truncatedSummary(article)
|
self.summary = ArticleStringFormatter.truncatedSummary(article)
|
||||||
|
|
||||||
self.dateString = ArticleStringFormatter.dateString(article.logicalDatePublished)
|
self.dateString = ArticleStringFormatter.dateString(article.logicalDatePublished)
|
||||||
|
@ -60,6 +62,7 @@ struct MasterTimelineCellData {
|
||||||
|
|
||||||
init() { //Empty
|
init() { //Empty
|
||||||
self.title = ""
|
self.title = ""
|
||||||
|
self.attributedTitle = NSAttributedString()
|
||||||
self.summary = ""
|
self.summary = ""
|
||||||
self.dateString = ""
|
self.dateString = ""
|
||||||
self.feedName = ""
|
self.feedName = ""
|
||||||
|
|
|
@ -148,7 +148,7 @@ private extension MasterTimelineTableViewCell {
|
||||||
func updateTitleView() {
|
func updateTitleView() {
|
||||||
titleView.font = MasterTimelineDefaultCellLayout.titleFont
|
titleView.font = MasterTimelineDefaultCellLayout.titleFont
|
||||||
titleView.textColor = labelColor
|
titleView.textColor = labelColor
|
||||||
updateTextFieldText(titleView, cellData?.title)
|
updateTextFieldAttributedText(titleView, cellData?.attributedTitle)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateSummaryView() {
|
func updateSummaryView() {
|
||||||
|
@ -171,6 +171,19 @@ private extension MasterTimelineTableViewCell {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updateTextFieldAttributedText(_ label: UILabel, _ text: NSAttributedString?) {
|
||||||
|
var s = text ?? NSAttributedString(string: "")
|
||||||
|
|
||||||
|
if let fieldFont = label.font, let color = label.textColor {
|
||||||
|
s = s.adding(font: fieldFont, color: color)
|
||||||
|
}
|
||||||
|
|
||||||
|
if label.attributedText != s {
|
||||||
|
label.attributedText = s
|
||||||
|
setNeedsLayout()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func updateFeedNameView() {
|
func updateFeedNameView() {
|
||||||
switch cellData.showFeedName {
|
switch cellData.showFeedName {
|
||||||
case .feed:
|
case .feed:
|
||||||
|
|
Loading…
Reference in New Issue