UIButton with UITableViewCellSelectionStyleGray Selection Color

后端 未结 3 632
野性不改
野性不改 2021-01-19 14:42

I am trying to set the selected color for a UIButton to the color of \'UITableViewCellSelectionStyleGray\'; The problem is that the selection color of a UIButton cannot be s

3条回答
  •  广开言路
    2021-01-19 15:28

    When you set the tintColor property on a UIButton, the color is set on the highlighted state. So you could do this:

    [button setTintColor:[UIColor lightGrayColor]];
    

    However, lightGrayColor may not be the exact gray you're looking for. I'm not aware of a way to get reference to the exact selection-gray of a UITableViewCell. You might just have to play with [UIColor colorWithRed:green:blue:alpha:] to get it like you want it.

    **Also not that the tintColor property has different implications in iOS 7, so beware of that if you use this code.

提交回复
热议问题