我有一个非常简单的单元格,我希望在聚焦时文本为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
}
}
但是,我不想在聚焦时想要白色背景......如何摆脱它?
答案 0 :(得分:3)
设置你的细胞' focusStyle
到UITableViewCellFocusStyleCustom
,UIKit根本不会在细胞上做任何默认焦点外观:它完全取决于你。