如何更改表格单元格的详细信息披露按钮的颜色

问题描述:

我想更改表格单元格的详细信息披露按钮的颜色。在此先感谢。

I want to change the color of detail disclosure button of a table cell. Thanks in advance.


您必须创建自定义 UIButton 并将其设置为单元格的 accessoryView

You have to create a custom UIButton and set it as cell's accessoryView.

您的 cellForRowAtIndexPath:会看起来像什么如下所示,

Your cellForRowAtIndexPath: will look something like the following,

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    //...

    if (cell == nil) {

        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];

        UIButton *myAccessoryButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
        [myAccessoryButton setBackgroundColor:[UIColor clearColor]];
        [myAccessoryButton setImage:[UIImage imageNamed:@"my_red_accessory_image"] forState:UIControlStateNormal];
        [cell setAccessoryView:myAccessoryButton];
        [myAccessoryButton release];

        //...
    }

    //...
}