在UITableViewCell上动态更改字体时UILabel闪烁

时间:2015-05-08 15:12:01

标签: ios objective-c iphone uitableview swift

tableView.estimatedRowHeight = 90.0
tableView.rowHeight = UITableViewAutomaticDimension
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    //ask for a reusable cell from the tableview, the tableview will create a new one if it doesn't have any
    let cell = self.tableView.dequeueReusableCellWithIdentifier("DetailCell") as DetailCell

    var detail : Detail
    detail = Details[indexPath.row]

    var paragraphStyle = NSMutableParagraphStyle()
    paragraphStyle.lineSpacing = 15
    paragraphStyle.alignment = NSTextAlignment.Right

    var attrString = NSMutableAttributedString(string: detail.detailText)
    attrString.addAttribute(NSParagraphStyleAttributeName, value:paragraphStyle, range:NSMakeRange(0, attrString.length))

    var fontName = cell.myLabel.font.fontName

    cell.myLabel.font = UIFont(name:fontName, size: pointSize)
    cell.myLabel.attributedText = attrString


    return cell
}
@IBAction func pinched(sender: UIPinchGestureRecognizer)
{
    pointSize = ((sender.velocity > 0) ? 1 : -1) * 0.5 + pointSize;

    if (pointSize < MIN_SIZE)
    {
        pointSize = MIN_SIZE
    }
    else if (pointSize > MAX_SIZE)
    {
        pointSize = MAX_SIZE
    }
    self.tableView.reloadData()
}

pointSize随着用户的压缩而变化(使用UIPinchRecognizer) myLabel的默认pointSize为17。 当收缩以增加或减少pointSize时,代码可以正常工作。 但是首先滚动时会应用默认大小,然后增加或减小大小,因此在滚动时单元格会产生闪烁效果。

我该如何避免这种情况? 是否已为UITableViewCells

完成任何示例示例

0 个答案:

没有答案
相关问题