heightOfFeed of FeedSocialWorkCell

This commit is contained in:
nixzhu
2015-11-19 18:35:20 +08:00
parent e74160b9b3
commit 71d035e9ac
3 changed files with 48 additions and 5 deletions
@@ -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
+1 -1
View File
@@ -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"
@@ -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)
}
}