很多时候我们需要做不同版本的适配,所以首先要进行版本选择
- 方式一
<span class="line-number" style="color: inherit !important;">1</span> <span class="line-number" style="color: inherit !important;">2</span> <span class="line-number" style="color: inherit !important;">3</span> <span class="line-number" style="color: inherit !important;">4</span> <span class="line-number" style="color: inherit !important;">5</span> <span class="line-number" style="color: inherit !important;">6</span> <span class="line-number" style="color: inherit !important;">7</span> <span class="line-number" style="color: inherit !important;">8</span> <span class="line-number" style="color: inherit !important;">9</span> <span class="line-number" style="color: inherit !important;">10</span> <span class="line-number" style="color: inherit !important;">11</span> <span class="line-number" style="color: inherit !important;">12</span> <span class="line-number" style="color: inherit !important;">13</span> |
|
- 方式二
<span class="line-number" style="color: inherit !important;">1</span> <span class="line-number" style="color: inherit !important;">2</span> <span class="line-number" style="color: inherit !important;">3</span> <span class="line-number" style="color: inherit !important;">4</span> <span class="line-number" style="color: inherit !important;">5</span> |
|
新的barTintColor
iOS7 中新增了barTintColor
来取代原有的 tintColor
, 现在barTintColor
表示对背景色的修改,而原有的tintColor
只修改对应bar上的按钮
自定义 UIBarButtonItem 偏移
在iOS7中自定义的 UIBarButtonItem
所有的item向中间偏移了5个像素,所以需要修改alignmentRectInsets
来适配, 例如
<span class="line-number" style="color: inherit !important;">1</span> <span class="line-number" style="color: inherit !important;">2</span> <span class="line-number" style="color: inherit !important;">3</span> <span class="line-number" style="color: inherit !important;">4</span> <span class="line-number" style="color: inherit !important;">5</span> <span class="line-number" style="color: inherit !important;">6</span> <span class="line-number" style="color: inherit !important;">7</span> <span class="line-number" style="color: inherit !important;">8</span> <span class="line-number" style="color: inherit !important;">9</span> <span class="line-number" style="color: inherit !important;">10</span> <span class="line-number" style="color: inherit !important;">11</span> <span class="line-number" style="color: inherit !important;">12</span> <span class="line-number" style="color: inherit !important;">13</span> <span class="line-number" style="color: inherit !important;">14</span> |
|
edgesForExtendedLayout 是什么
edgesForExtendedLayout是一个类型为UIExtendedEdge的属性,指定边缘要延伸的方向。 因为iOS7鼓励全屏布局,它的默认值很自然地是UIRectEdgeAll,四周边缘均延伸,就是说,如果即使视图中上有navigationBar,下有tabBar,那么视图仍会延伸覆盖到四周的区域。
如果把视图做如下设置,那么视图就不会延伸到这些bar的后面了.
<span class="line-number" style="color: inherit !important;">1</span> |
|
一些相关的属性
<span class="line-number" style="color: inherit !important;">1</span> |
|
在iOS7中如果视图里面存在唯一一个UIScrollView或其子类View,那么它会自动设置相应的内边距,这样可以让scroll占据整个视图,又不会让导航栏遮盖.
<span class="line-number" style="color: inherit !important;">1</span> |
|
最后一个介绍的新属性是extendedLayoutIncludesOpaqueBars,这个属性指定了当Bar使用了不透明图片时,视图是否延伸至Bar所在区域,默认值时NO。
grouped 的变化
在iOS7 中UITableView的grouped延伸至两边变成了通栏.里面的控件用autolayout来兼容
PS: 一个不是问题的问题,在XCode5中如果是一个xib创建的grouped的tableView,将不会正常显示,需要重新初始化,例如
<span class="line-number" style="color: inherit !important;">1</span> <span class="line-number" style="color: inherit !important;">2</span> <span class="line-number" style="color: inherit !important;">3</span> <span class="line-number" style="color: inherit !important;">4</span> <span class="line-number" style="color: inherit !important;">5</span> <span class="line-number" style="color: inherit !important;">6</span> <span class="line-number" style="color: inherit !important;">7</span> <span class="line-number" style="color: inherit !important;">8</span> <span class="line-number" style="color: inherit !important;">9</span> <span class="line-number" style="color: inherit !important;">10</span> <span class="line-number" style="color: inherit !important;">11</span> |
|
一些情况下 window.tintColor 的使用
如果不为窗体指定着色,则会使用系统默认的颜色。
默认情况下,视图的着色是nil,意味着视图使用父级的着色。也就是说哪怕你不设置着色的话,视图也总能够获取到一个色值。
总的来说,最好在视图还没有显示到屏幕上之前指定它的着色。想让视图继承上个层级的着色的话,就将着色设置为nil。
info.plist 中的View controller-based status bar appearance
如果你想要隐藏status bar, 或者用原来的方式修改status bar的颜色.在info.plist中增加这个属性,并且设置为NO
UITextView 的改变
这个请参考 stackover flow
消失的search bar
PS: 另一个不是问题的问题,把searchBar 当做tableView的header的时候,如果含有UISearchDisplayController,有时候会导致search bar消失. 目前没有找到很好的办法,目前重新初始化可以解决.
<span class="line-number" style="color: inherit !important;">1</span> <span class="line-number" style="color: inherit !important;">2</span> <span class="line-number" style="color: inherit !important;">3</span> <span class="line-number" style="color: inherit !important;">4</span> <span class="line-number" style="color: inherit !important;">5</span> <span class="line-number" style="color: inherit !important;">6</span> <span class="line-number" style="color: inherit !important;">7</span> |
|
新的UITableViewCellScrollView
在iOS7之前UITablleViewCell中得contentView得superView就是UITableViewCell。但是在iOS7得时候,contentView得superView确实UITableViewCellScrollView.可以用以下代码来获取
<span class="line-number" style="color: inherit !important;">1</span> <span class="line-number" style="color: inherit !important;">2</span> <span class="line-number" style="color: inherit !important;">3</span> <span class="line-number" style="color: inherit !important;">4</span> <span class="line-number" style="color: inherit !important;">5</span> <span class="line-number" style="color: inherit !important;">6</span> <span class="line-number" style="color: inherit !important;">7</span> <span class="line-number" style="color: inherit !important;">8</span> <span class="line-number" style="color: inherit !important;">9</span> <span class="line-number" style="color: inherit !important;">10</span> <span class="line-number" style="color: inherit !important;">11</span> <span class="line-number" style="color: inherit !important;">12</span> <span class="line-number" style="color: inherit !important;">13</span> <span class="line-number" style="color: inherit !important;">14</span> <span class="line-number" style="color: inherit !important;">15</span> <span class="line-number" style="color: inherit !important;">16</span> |
|