在WatchKit中以编程方式更改行的颜色 [英] Change color of row programmatically in WatchKit
问题描述
如果要选择WKInterfaceTable中的行,我想更改它的颜色.我已经完成了这些步骤,但是不知道该怎么做:
I'd like to change the color of a row in a WKInterfaceTable if it has been selected. I've done these steps but don't know how I can go further:
override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) {
let row = tableView.rowControllerAtIndex(rowIndex) as! TableRowObject
}
我希望你们中有人能帮助我做到这一点.
I hope someone of you guys can help me to do this.
推荐答案
您可以根据行选择更改颜色,
You can change colour as per row selection,
在rowController中创建WKInterfaceGroup的IBOutlet并将其设置为带有DefaultGroup的Storyboard,这是将Table拖动到Storyboard时创建的(无需添加新的WKInterfaceGroup).
Create IBOutlet of WKInterfaceGroup in rowController and set it to Storyboard with DefaultGroup which is created when you drag Table to storyboard (no need to add new WKInterfaceGroup).
@property (weak, nonatomic) IBOutlet WKInterfaceGroup *rowGroup;
创建一个BOOL属性以跟踪rowController中的选择状态.
Create a BOOL property to track selection status in rowController.
@property (nonatomic, readwrite) BOOL isSelected;
将此添加到didSelectRow中,
Add this to didSelectRow,
- (void)table:(WKInterfaceTable *)table didSelectRowAtIndex:(NSInteger)rowIndex {
TableRowObject *row = [self.interfaceTable rowControllerAtIndex:rowIndex];
if (row.isSelected) {
row.isSelected = NO;
[row.rowGroup setBackgroundColor:[UIColor clearColor]];
}
else {
row.isSelected = YES;
[row.rowGroup setBackgroundColor:[UIColor blueColor]];
}
}
这篇关于在WatchKit中以编程方式更改行的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!