MIN() and MAX() in Swift and converting Int to CGFloat
- by gotnull
I'm getting some errors with the following methods:
1) How do I return screenHeight / cellCount as a CGFLoat for the first method?
2) How do I use the equivalent of ObjC's MIN() and MAX() in the second method?
func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat {
var cellCount = Int(self.tableView.numberOfRowsInSection(indexPath.section))
return screenHeight / cellCount as CGFloat
}
// #pragma mark - UIScrollViewDelegate
func scrollViewDidScroll(scrollView: UIScrollView) {
let height = CGFloat(scrollView.bounds.size.height)
let position = CGFloat(MAX(scrollView.contentOffset.y, 0.0))
let percent = CGFloat(MIN(position / height, 1.0))
blurredImageView.alpha = percent
}