better logic of footerCellHeight

This commit is contained in:
nixzhu
2015-03-18 15:47:50 +08:00
parent ceed017120
commit cbecfc2d04
2 changed files with 11 additions and 7 deletions
@@ -39,6 +39,13 @@ class ProfileViewController: UIViewController {
@IBOutlet weak var profileCollectionView: UICollectionView!
lazy var footerCellHeight: CGFloat = {
let attributes = [NSFontAttributeName: profileIntroductionLabelFont]
let labelWidth = screenWidth - (profileIntroductionLabelLeadingSpaceToContainer + profileIntroductionLabelTrailingSpaceToContainer)
let rect = introductionText.boundingRectWithSize(CGSize(width: labelWidth, height: CGFloat(FLT_MAX)), options: .UsesLineFragmentOrigin | .UsesFontLeading, attributes:attributes, context:nil)
return ceil(rect.height)
}()
override func viewDidLoad() {
super.viewDidLoad()
@@ -200,12 +207,7 @@ extension ProfileViewController: UICollectionViewDataSource, UICollectionViewDel
return CGSizeMake(cellWidth, cellHeight)
case ProfileSection.Footer.rawValue:
let attributes = [NSFontAttributeName: UIFont(name: "HelveticaNeue-Thin", size: 12)!]
let labelWidth = screenWidth - (profileIntroductionLabelLeadingSpaceToContainer + profileIntroductionLabelTrailingSpaceToContainer)
let rect = introductionText.boundingRectWithSize(CGSize(width: labelWidth, height: CGFloat(FLT_MAX)), options: .UsesLineFragmentOrigin | .UsesFontLeading, attributes:attributes, context:nil)
return CGSizeMake(screenWidth, ceil(rect.height))
return CGSizeMake(screenWidth, footerCellHeight)
default:
return CGSizeZero
@@ -10,13 +10,13 @@ import UIKit
let profileIntroductionLabelLeadingSpaceToContainer: CGFloat = 20
let profileIntroductionLabelTrailingSpaceToContainer: CGFloat = 20
let profileIntroductionLabelFont = UIFont(name: "HelveticaNeue-Thin", size: 12)!
class ProfileFooterCell: UICollectionViewCell {
@IBOutlet weak var instroductionLabelLeftConstraint: NSLayoutConstraint!
@IBOutlet weak var instroductionLabelRightConstraint: NSLayoutConstraint!
@IBOutlet weak var introductionLabel: UILabel!
override func awakeFromNib() {
@@ -24,6 +24,8 @@ class ProfileFooterCell: UICollectionViewCell {
instroductionLabelLeftConstraint.constant = profileIntroductionLabelLeadingSpaceToContainer
instroductionLabelRightConstraint.constant = profileIntroductionLabelTrailingSpaceToContainer
introductionLabel.font = profileIntroductionLabelFont
}
}