zoukankan      html  css  js  c++  java
  • 适配iOS7之—UITableView和UISearchBar

    iOS7中,如果用UITableViewStyleGrouped的话,里面的cell会比原来的拉长了,这样做应该是为了统一和UITableViewStylePlain风格时cell的大小一致,所以改用UITableViewStylePlain后,就没问题了,而且在iOS7中,使用UITableViewStyleGrouped风格时,上面会出现headView,大概占了35个像素,使用UITableViewStyleGrouped风格的朋友们注意了,如下图为使用UITableViewStyleGrouped时的差异:屏幕快照 2013-09-27 下午10.27.49

    图1-1

    还有就是iOS7下的UITableView增加了一个UITableViewWrapperView子视图,UITableViewCell变成了UITableViewWrapperView的子视图,而在iOS6中,UITableViewCell是UITableView的子视图。

    用代码表现出来就是:

    1
    2
    3
    UITableView *tableView = (UITableView *)cell.superview.superview;//in iOS7
     
    UITableView *tableView = (UITableView *)cell.superview;//in iOS6

    如果之前定制cell的时候,用下面代码取tableView的需要做适配了。

    1
    UITableView *tableView = (UITableView *)self.superview;

    还有就是现在可以直接设置UITableView的背景颜色了:

    1
    _loginTable.backgroundColor = [UIColor redColor];

    另一个问题就是我使用UISearchBar的时候,Apple在iOS7中也做了调整。如下图:

    屏幕快照 2013-09-27 下午11.22.03

    图1-2

    相信很多人在使用UISearchBar的时候,都比较喜欢上面的那种去了背景色的样子,在iOS6中我是使用下面这种方式去除背景色:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    //for iOS6
    for (UIView *subview in self.search.subviews) {
     
        if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
     
            [subview removeFromSuperview];
     
            break;
     
        }
     
    }

    而今天突然发现,纳尼,在iOS7中,搜索框消失了,用小伙伴的方法看了一下,原来视图树改变了。如下图:

    uisearchbar

    在iOS7中,UISearchBar的子视图变成一个UIView,所以原来的方法不管用了,但是看了一下文档,在iOS7中新增了一个barTintColor的属性,我们可以设置barTintColor为clearColor,便得到图1-2中的效果。

    1
    2
    3
    4
    5
    6
    7
    //for iOS 7
     
    if ([self.search respondsToSelector:@selector(barTintColor)]) {
     
    [self.search setBarTintColor:[UIColor clearColor]];
     
    }

    至此,目前我在适配iOS7的时候,就遇到这两个问题,写出来,分享给大家。

    今天看到一个笑话,快笑得不能自已了:

    为什么练葵花宝典一定要先自宫?

    网友答复:练成神功后,绝对会屌爆了,所以要先防患于未然。O(∩_∩)O~

  • 相关阅读:
    Mysql登录错误:ERROR 1045 (28000): Plugin caching_sha2_password could not be loaded
    Docker配置LNMP环境
    Docker安装mysqli扩展和gd扩展
    Docker常用命令
    Ubuntu常用命令
    单例模式的优缺点和使用场景
    ABP 多租户数据共享
    ABP Core 后台Angular+Ng-Zorro 图片上传
    ERROR Error: If ngModel is used within a form tag, either the name attribute must be set or the form control must be defined as 'standalone' in ngModelOptions.
    AbpCore 执行迁移文件生成数据库报错 Could not find root folder of the web project!
  • 原文地址:https://www.cnblogs.com/yingkong1987/p/3344067.html
Copyright © 2011-2022 走看看