Skip to content

Instantly share code, notes, and snippets.

@AlehUlitsionak
Last active August 29, 2015 14:18
Show Gist options
  • Save AlehUlitsionak/9016b28351d6ed47dc0d to your computer and use it in GitHub Desktop.
Save AlehUlitsionak/9016b28351d6ed47dc0d to your computer and use it in GitHub Desktop.
func rowHeightForRowWithIndexPath(indexPath: NSIndexPath) -> CGFloat {
var identifier = self.segmentBar.selectedSegmentIndex == 0 ? "DataCellDefault" : "DataCellExcerpt"
let cell = tableView.dequeueReusableCellWithIdentifier(identifier) as DataTableViewCell
let dataItem = self.data[indexPath.section]
var result = CGFloat(0)
var sideMargin = CGFloat(8)
var screenWidth = UIScreen.mainScreen().bounds.width
var labelWidth = screenWidth - (2 * sideMargin)
if dataItem.imageUrl == "" {
result += sideMargin
if let postTitleLabel = cell.viewWithTag(101) as? UILabel {
postTitleLabel.text = dataItem.postTitle
result += postTitleLabel.sizeThatFits(CGSizeMake(labelWidth, CGFloat(FLT_MAX))).height
result += 2
}
if let authorNameLabel = cell.viewWithTag(102) as? UILabel {
authorNameLabel.text = dataItem.authorName
result += authorNameLabel.sizeThatFits(CGSizeMake(labelWidth, CGFloat(FLT_MAX))).height
result += sideMargin + 1
}
}
else {
result = cell.imageViewWidth
}
if self.segmentBar.selectedSegmentIndex == 1 {
if let excerptLabel = cell.viewWithTag(104) as? UILabel {
excerptLabel.text = dataItem.excerpt
result += 5
result += excerptLabel.sizeThatFits(CGSizeMake(labelWidth, CGFloat(FLT_MAX))).height
result += 3
}
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment