不要为UITableViewCell使用默认焦点动画

时间:2015-11-19 00:13:06

标签: uitableview focus tvos

我有一个非常简单的单元格,我希望在聚焦时文本为1.0 alpha,在未聚焦时为0.5。这可以通过覆盖didUpdateFocusInContext

来实现
import Foundation

class SettingsTableViewCell: UITableViewCell {


override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
    super.didUpdateFocusInContext(context, withAnimationCoordinator: coordinator)

    var textColor:UIColor?

    if self.focused == true {
        textColor = UIColor.blackColor().colorWithAlphaComponent(1.0)
    } else {
        textColor = UIColor.blackColor().colorWithAlphaComponent(0.5)
    }

    let attributedTitle = self.textLabel?.attributedText?.mutableCopy() as! NSMutableAttributedString
    let range =  NSMakeRange(0, attributedTitle.length)
    attributedTitle.addAttribute(NSForegroundColorAttributeName, value: textColor!, range: range)
    self.textLabel?.attributedText = attributedTitle

}

}

但是,我不想在聚焦时想要白色背景......如何摆脱它?

enter image description here

1 个答案:

答案 0 :(得分:3)

设置你的细胞' focusStyleUITableViewCellFocusStyleCustom,UIKit根本不会在细胞上做任何默认焦点外观:它完全取决于你。