From 71d035e9acfc9e1bcdbd5a06dbc752a20ea6270f Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 19 Nov 2015 18:35:20 +0800 Subject: [PATCH] heightOfFeed of FeedSocialWorkCell --- .../Feeds/FeedsViewController.swift | 11 ++++- Yep/Views/Cells/Feed/FeedCell.swift | 2 +- .../FeedSocialWork/FeedSocialWorkCell.swift | 40 +++++++++++++++++-- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index 8414130f..372ef958 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -114,7 +114,16 @@ class FeedsViewController: BaseViewController { return height } else { - let height = FeedCell.heightOfFeed(feed) + + let height: CGFloat + switch feed.kind { + case .Normal: + height = FeedCell.heightOfFeed(feed) + case .GithubRepo, .DribbbleShot: + height = FeedSocialWorkCell.heightOfFeed(feed) + default: + height = FeedCell.heightOfFeed(feed) + } if !key.isEmpty { feedHeightHash[key] = height diff --git a/Yep/Views/Cells/Feed/FeedCell.swift b/Yep/Views/Cells/Feed/FeedCell.swift index d51cab23..d241e8fc 100644 --- a/Yep/Views/Cells/Feed/FeedCell.swift +++ b/Yep/Views/Cells/Feed/FeedCell.swift @@ -58,7 +58,7 @@ class FeedCell: UITableViewCell { static let messageTextViewMaxWidth: CGFloat = { let maxWidth = UIScreen.mainScreen().bounds.width - (15 + 40 + 10 + 15) return maxWidth - }() + }() let feedMediaCellID = "FeedMediaCell" diff --git a/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift b/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift index ddcd72b1..8b263db1 100644 --- a/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift +++ b/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.swift @@ -30,10 +30,27 @@ class FeedSocialWorkCell: UITableViewCell { @IBOutlet weak var distanceLabel: UILabel! @IBOutlet weak var messageCountLabel: UILabel! - + + static let messageTextViewMaxWidth: CGFloat = { + let maxWidth = UIScreen.mainScreen().bounds.width - (15 + 40 + 10 + 60) + return maxWidth + }() + override func awakeFromNib() { super.awakeFromNib() - // Initialization code + + nicknameLabel.textColor = UIColor.yepTintColor() + messageTextView.textColor = UIColor.yepMessageColor() + distanceLabel.textColor = UIColor.grayColor() + timeLabel.textColor = UIColor.grayColor() + dotLabel.textColor = UIColor.grayColor() + messageCountLabel.textColor = UIColor.yepTintColor() + skillLabel.textColor = UIColor.yepTintColor() + + messageTextView.font = UIFont.feedMessageFont() + messageTextView.textContainer.lineFragmentPadding = 0 + messageTextView.textContainerInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) + messageTextView.dataDetectorTypes = .Link } override func setSelected(selected: Bool, animated: Bool) { @@ -41,5 +58,22 @@ class FeedSocialWorkCell: UITableViewCell { // Configure the view for the selected state } - + + class func heightOfFeed(feed: DiscoveredFeed) -> CGFloat { + + let rect = feed.body.boundingRectWithSize(CGSize(width: FeedSocialWorkCell.messageTextViewMaxWidth, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedCell.textAttributes, context: nil) + + var height: CGFloat = ceil(rect.height) + 10 + 40 + 4 + 15 + 17 + 15 + switch feed.kind { + case .GithubRepo: + height += (80 + 15) + case .DribbbleShot: + height += (80 + 15) + default: + break + } + + return ceil(height) + } } +