ios7适配--uitableviewcell选中效果

简介:

ios7 UITableViewCell selectionStyle won't go back to blue

Xcode 5.0, iOS 7 and updating an existing app. UITableView selected row is now gray, not blue.

From what I've read they changed the default selectionStyle to gray. But "Blue" is still an option in IB and UITableViewCellSelectionStyleBlue still exists. Checking out the new HIG, it doesn't look like they removed the blue and the "Settings" app still using blue cell selection.

I've tried setting the value in IB and in code, but no luck. Any ideas on what I need to do to get the blue selection style back?

share | edit | flag
 
   
   
I am unable to check it out right now, but in the cellForRowAtIndexPath method, it does not work to use the statement, cell.selectionStyle = UITableViewCellSelectionStyleBlue;? –  for i in range awesome Sep 13 at 20:50
   
   
Just tested it out- it does not work. I will try to figure it out and get back to you if I can fix it –  for i in range awesome  Sep 13 at 21:12
   
add comment

2 Answers

up vote 1 down vote accepted

There is only one selectionStyle in iOS7, to change you need to do this manually like below:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ 
    ....
    UIView *bgColorView = [[UIView alloc] init];
    bgColorView.backgroundColor = [UIColor blueColor];
    bgColorView.layer.masksToBounds = YES;
    cell.selectedBackgroundView = bgColorView;
    ....
    return cell;
}
share | edit | flag
 
   
   
I was thinking about trying something like this- only problem is that blueColor is the ugliest possible shad of blue for this. If someone wants to actually use this in an app, then it would require using RGB combos for a better color – for i in range awesome Sep 14 at 16:38
   
   
So what I'm hearing is, blue as a default either no longer exists or isn't functioning properly. That was pretty much my conclusion too, but it seems awfully strange they wouldn't take it out of the UI or deprecate it if wasn't going to have a future. – DBD Sep 16 at 12:31
   
   
While not overly happy with this answer, this type of approach does seem to be the only which currently works (hopefully that will change soon). So I'm marking as the accepted answer. – DBD Sep 19 at 12:52
   
   
I agree, but what to do? it is not the best solution but apparently it is the only way to do the job, Apple has taken some actions in iOS7 made a lot of developers unhappy, for example you cannot add subview in UIActionSheet any more! this is really sad especially there is no workaround like your case and you should use another custom component rather than ActionSheet. – null Sep 19 at 15:24
   
add comment

Probably it could help you. I have my custom cell and to make it selected with needed color I have overwrite setHighlighted and setSelected now it's look like that

#define IOS_7 (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1 ? YES : NO)


    - (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    [self changeSelectionColorForSelectedORHiglightedState:selected];
    // Configure the view for the selected state
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
    [super setHighlighted:highlighted animated:animated];
    [self changeSelectionColorForSelectedORHiglightedState:highlighted];
}

- (void)changeSelectionColorForSelectedORHiglightedState:(BOOL)state
{
    if (IOS_7) {
        if (state) {
            self.contentView.backgroundColor = [UIColor blueColor];
        }
    }
}
share | edit | flag
  add comment
欢迎加群互相学习,共同进步。QQ群:iOS: 58099570 | Android: 572064792 | Nodejs:329118122 做人要厚道,转载请注明出处!















本文转自张昺华-sky博客园博客,原文链接: http://www.cnblogs.com/sunshine-anycall/p/3342246.html ,如需转载请自行联系原作者
相关文章
|
29天前
|
IDE API Android开发
安卓与iOS开发环境的差异及适配策略
在移动应用开发的广阔舞台上,Android和iOS两大操作系统各据一方,各自拥有独特的开发环境和工具集。本文旨在深入探讨这两个平台在开发环境上的关键差异,并提供有效的适配策略,帮助开发者优化跨平台开发流程。通过比较Android的Java/Kotlin和iOS的Swift/Objective-C语言特性、IDE的选择、以及API和系统服务的访问方式,本文揭示了两个操作系统在开发实践中的主要分歧点,并提出了一套实用的适配方法,以期为移动开发者提供指导和启示。
|
3月前
|
iOS开发
SwiftUI适配iOS16导航控制器引起的闪退
SwiftUI适配iOS16导航控制器引起的闪退
46 0
|
3月前
|
iOS开发
iOS UITableViewCell刷新某些行的cell或section
iOS UITableViewCell刷新某些行的cell或section
29 0
|
3月前
|
监控 iOS开发
iOS15适配问题:viewForSupplementaryElementOfKind表头和表尾复用闪退,UITableView section header多22像素等问题
iOS15适配问题:viewForSupplementaryElementOfKind表头和表尾复用闪退,UITableView section header多22像素等问题
38 0
|
9月前
|
小程序 开发工具 Android开发
Donut多端框架小程序打包适配ios和安卓app
腾讯新出了一个 Donut 多端框架,可以直接将微信小程序转成 ios 和 安卓 app,小程序开发者工具里也集成了 app 相关升级、调试和打包的功能,终于可以一套代码开发出3个客户端了!
201 0
Donut多端框架小程序打包适配ios和安卓app
|
10月前
|
安全 前端开发 开发工具
iOS12、iOS11、iOS10、iOS9常见适配
iOS12、iOS11、iOS10、iOS9常见适配
194 0
|
11月前
|
小程序 iOS开发
uniapp中IOS端小程序底部黑线适配的方法(整理)
uniapp中IOS端小程序底部黑线适配的方法(整理)
|
开发工具 iOS开发 开发者
iOS 暗黑模式的适配总结
iOS 暗黑模式的适配总结
|
安全 iOS开发
iOS小技能:下拉刷新控件的适配
1. 下拉顶部背景色设置: 往tableView的父控件添加拉伸背景视图 2. present 半屏适配 iOS13 modalPresentationStyle属性默认不是全屏样式`UIModalPresentationFullScreen`,而是半屏样式,需要根据需求手动设置。 present 半屏,会导致列表下拉刷新失效。
192 0
iOS小技能:下拉刷新控件的适配
|
Web App开发 移动开发 前端开发
HTML5 移动端页面适配 iOS 系统刘海屏
HTML5 移动端页面适配 iOS 系统刘海屏
1184 0
HTML5 移动端页面适配 iOS 系统刘海屏