在WatchKit中以编程方式更改行的颜色 [英] Change color of row programmatically in WatchKit

查看:93
本文介绍了在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆