【发布时间】:2015-11-19 00:13:05
【问题描述】:
我有一个非常简单的单元格,我希望文本在聚焦时为 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
}
}
但是,我不想要聚焦时的白色背景...如何摆脱它?
【问题讨论】:
标签: uitableview focus tvos