Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
712 views
in Technique[技术] by (71.8m points)

ios - Why can't you set the cell.selectionStyle = UITableViewCellSelectionStyleBlue?

I have seen the following questions, but non explain that while you can simply set cell.SelectedStyle to UITableViewCellSelectionStyleGray or UITableViewCellSelectionStyleNone, you can't set it selectionStyle to UITableViewCellSelectionStyleBlue.

They just offer a hack without explaining. I simply want to know the why so that I can better understand objective-c

UITableViewCellSelectionStyleBlue is not working

ios7 UITableViewCell selectionStyle won't go back to blue

Cannot change UITableView blue highlight color

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your not going to like the answer then. As of iOS 7, setting

cell.selectionStyle = UITableViewCellselectionStyleBlue;

will now give you gray. Apple got rid of it in iOS 7, so now selectionStyleBlue no longer exists as blue.. it is gray.

Here is the quote from Apple's Documentation of the UITableViewCell Class Reference:

  • Blue

The cell has a default background color when selected.

In iOS 7, the selection color is no longer blue. Use UITableViewCellSelectionStyleDefault instead.

Available in iOS 2.0 and later.

Of course, as I'm sure you have found, you can create a UIView and set it as the background to simulate a blue selection.

Here is a link for that approach: UITableView cell blue highlight on selection

Edit:

Just to be clear. UITableViewCellSelectionStyleBlue makes the selection style gray.

There is no default method of UITableViewCell that makes selection style a blue color.

In order to make selection style any color other than the default gray, you have to create a custom UIView like in the link I provided.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...