ios7新增長的icon尺寸:javascript
76 x 76:Size for iPad 2 and iPad mini (standard resolution)html
120 x 120 :Size for iPhone and iPod touch (high resolution)java
152 x 152: Size for iPad and iPad mini (high resolution)ios
參考:xcode
http://blog.manbolo.com/2013/08/15/new-metrics-for-ios-7-app-iconsapp
https://developer.apple.com/library/ios/documentation/userexperience/conceptual/mobilehig/IconMatrix.htmlide
Launch image工具
原來作ios5,6的啓動畫面時,若是有status bar,咱們會考慮作一張高度少20point的圖片,如今ios7的status bar透明瞭,因此Launch image須要作成全屏尺寸。佈局
在xcode5中同時預覽ios7和ios7之前的ui樣式:測試
一、打開須要預覽的xib;
二、打開assistant editor;
三、點擊Manual選擇Pre view
判斷ios7:
- #define NLSystemVersionGreaterOrEqualThan(version) ([[[UIDevice currentDevice] systemVersion] floatValue] >= version)
- #define IOS7_OR_LATER NLSystemVersionGreaterOrEqualThan(7.0)
-
- #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1
- if (IOS7_OR_LATER) {
-
- }
- #endif
ps:一個不錯的宏:
- #ifndef kCFCoreFoundationVersionNumber_iOS_6_1
- #define kCFCoreFoundationVersionNumber_iOS_6_1 793.00
- #endif
-
- #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1
- #define IF_IOS7_OR_GREATER(...) \
- if (kCFCoreFoundationVersionNumber > kCFCoreFoundationVersionNumber_iOS_6_1) \
- { \
- __VA_ARGS__ \
- }
- #else
- #define IF_IOS7_OR_GREATER(...)
- #endif
判斷SDK7:
- #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1
-
- #endif
判斷運行時方法:
- (BOOL)respondsToSelector:(SEL)aSelector;
例如:
- if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
- {
- self.edgesForExtendedLayout = UIRectEdgeNone;
- }
ios7中UITableView的cell separator默認不是從最左邊開始
下面兼容低於ios7的版本:
- #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
- if (IOS7_OR_LATER) {
- [tabelView setSeparatorInset:UIEdgeInsetsZero];
- }
- #endif
我這是自定義的xib的cell:原本是透明的uitableview背景,到ios7變成白色(由於背景是白色):
- 增長:
- cell.backgroundColor = [UIColor clearColor];
在以前的版本中UITableViewCell的backgroundColor是透明背景的,可是在iOS7中是默認白色背景,若是在TableView後面加入背景的應用要注意了,在建立UITableViewCell的時候把backgroundColor設置爲[UIColor clearColor]
UILabel不一致的background
對於UILabel,在iOS 7中它的background顏色默認是clearColor,而在iOS 6中默認的是白色。因此,咱們最好在代碼中對label的background顏色進行明確的設置:
- view.backgroundColor = [UIColor clearColor];
我這是自定義的xib的cell:用xib自定義的cell上的按鈕不能響應點擊事件,一種是把按鈕放到cell的contentView上,或者是設置[cell.contentView setUserInteractionEnabled: NO];來屏蔽cell上的點擊事件

若是你最近在作對iOS7的兼容時,發現你的table view cell顯示不正常。這極可能是你之前的用法不對。Table view cell的自定義內容應該做爲 cell.contentView的子view添加到cell中,若是你直接用 [cell addSubView:]方法而不是[cell.contentView addSubView:]方法添加子元素,那麼就可能在iOS7下出來異常的表現。主要緣由是iOS7的Table view cell內部實現有了部分變化。
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
-
- {
-
- UITableViewCell * cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:@"cellIdentifier"];
-
- UIView * subview = [[XXView alloc] init];
-
- subview.userInteractionEnabled = NO;
-
- subview.backgroundColor = [UIColor clearColor];
-
- subview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
-
- [cell.contentView addSubview:subview];
-
- return cell;
-
- }
在ios5,ios6中正常執行的動畫,但到ios7中不定時的會消失。
解決方案:在可能消失的地方加上「[UIView setAnimationsEnabled:YES]」,好比action方法,viewWillappear方法等。
網上暫時尚未與這個有關的問題,與這個相似:http://stackoverflow.com/questions/18880584/ios-7-animation-block-not-being-called

視圖控制器接口wantsFullScreenLayout已做廢。若是你像之前那樣地指定wantsFullScreenLayout = NO,iOS 7中視圖控制器會在將其內容顯示到一個意外的屏幕位置。
NSString 繪製
ios7 下使用
- (void)drawAtPoint:(CGPoint)point withAttributes:(NSDictionary *)attrs
進行繪製,須要定義attributes,對樣式進行定義。
例如attributes是@{NSFontAttributeName:[UIFontsystemFontOfSize:8], NSStrokeColorAttributeName:[[UIColorgreenColor] colorWithAlphaComponent:0.5]},但這個屬性會影響上下文。
ios7 以前使用
- (CGSize)drawAtPoint:(CGPoint)point withFont:(UIFont *)font 繪製。
navigation controller容器中佈局到ios7中往上偏移了64px
iOS6中默認的佈局將從navigation bar的底部開始,但到了iOS7中默認佈局從navigation bar的頂部開始,這就是爲何全部的UI元素都往上漂移了。由於在iOS7中,蘋果引入了一個新的屬性,叫作[UIViewController setEdgesForExtendedLayout:],它的默認值爲UIRectEdgeAll,使用edgesForExtendedLayout指定視圖的哪條邊須要擴展,不用理會操做欄的透明度。因此這種狀況快速修復的方法是:在-(void)viewDidLoad中添加以下一行代碼:
- self.edgesForExtendedLayout = UIRectEdgeNone;
extendedLayoutIncludesOpaqueBars
關於這個屬性的測試版本中默認值是YES,正式版本是NO!
若是你使用了不透明的navigation bar,設置edgesForExtendedLayout 仍是默認值UIRectEdgeAll,你又想整個view全屏(navigation bar下面的內容網上漂移64px) extendedLayoutIncludesOpaqueBars 的值設置爲YES。
例如:
- 在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法中給uinavigationbar設置背景圖片使之不透明:
- CGSize imageSize = CGSizeMake(1, 1);
- UIGraphicsBeginImageContextWithOptions(imageSize, YES, 0);
- [[UIColor greenColor] set];
- UIBezierPath * path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, imageSize.width, imageSize.height)];
- [path fill];
- UIImage *image = UIGraphicsGetImageFromCurrentImageContext ();
- UIGraphicsEndImageContext();
-
- [[UINavigationBar appearance] setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
而後在須要全屏的UIViewController中設置:
- self.extendedLayoutIncludesOpaqueBars = YES;
隱藏狀態條
原來在ios6中是:
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
-
- [[UIApplication sharedApplication] setStatusBarHidden:YES];
- return YES;
- }
如今在ios7中無效了。
快速解決:
在項目plist文件中修改成:
View controller-based status bar appearance 的值爲NO。
可是我認爲這個快速解決是沒有按照蘋果的思路來解決的,並且會有些問題,好比,當你在某個界面隱藏了status bar,退回到上一個界面時,status bar仍然是隱藏的。 首先,蘋果把View controller-based status bar appearance默認的值設爲YES,是有他的道理的,新系統下,蘋果但願咱們的viewcontroller去控制status bar,也就是說,咱們大多數的界面應該是統一的,偶爾一些viewcontroller須要status bar特殊控制的,徹底交給當前的viewcontroller來作。那麼推薦解決方案:
保持View controller-based status bar appearance 的默認值爲YES,而後在ViewController中重寫prefersStatusBarHidden方法:
- - (BOOL)prefersStatusBarHidden
- {
- return YES;
- }
狀態欄樣式修改:
在在UIViewController或子類中實現如下兩個方法:
- - (BOOL)prefersStatusBarHidden
- {
- return YES;
- }
- - (UIStatusBarStyle)preferredStatusBarStyle{
- return UIStatusBarStyleLightContent;
- }
在須要刷新狀態欄樣式的時候,調用
- - (void)setNeedsStatusBarAppearanceUpdate
在iOS7 UINavigationController中側滑手勢返回
假如你自定義leftBarButtonItem,返回手勢會失效,須要實現:
- self.navigationController.interactivePopGestureRecognizer.delegate = self;
假如你沒有自定義leftBarButtonItem或其餘需求而不須要手勢,必須實現:
- self.navigationController.interactivePopGestureRecognizer.enabled = NO;

在iOS 6 中,tintColor 能夠用來給導航欄的背景着色、tab 欄、工具欄、搜索欄、搜索欄的 範圍選擇欄着色。而在iOS 7 中,給背景着色只須要使用barTintColor 屬性就能夠了,因此iOS7中barTintColor 取代原有的 tintColor, 原有的tintColor只修改對應bar上的按鈕顏色。
Navigation Bar
也就是說若是設置Navigation Bar的圖片,而且這個圖片高度保持在44point(88px),那麼IOS5,6,7的效果是一致的。
參考:https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TransitionGuide/Bars.html#//apple_ref/doc/uid/TP40013174-CH8-SW1
UIBarButtonItem
在iOS7中自定義的 UIBarButtonItem 全部的item向中間偏移了,若是須要適配ios6的風格須要修改
簡單處理:
- UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
- initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
- target:nil action:nil];
- negativeSpacer.width = -16;
- [self.navigationItem setLeftBarButtonItems:[NSArray arrayWithObjects:negativeSpacer, requriedButton
若是想不修改源代碼,例如setLeftBarButtonItem等方法,能夠在category中覆蓋:

- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode)lineBreakMode 在ios7中過時
在ios7中使用:
- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(NSDictionary *)attributes context:(NSStringDrawingContext *)context
例如:
- CGSize size = CGSizeMake(screenSize.width - self.horizontalMargin * 4.f, 1000.f);
- if(IOS7_OR_LATER){
- CGRect textRect = [text boundingRectWithSize:size options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) attributes:@{NSFontAttributeName:font} context:nil];
- self.contentWidth = self.contentWidth!=0.f?self.contentWidth:textRect.size.width;
- self.contentHeight = self.contentHeight!=0.f?self.contentHeight:textRect.size.height;
- }else{
- CGSize textSize = [text sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap];
- self.contentWidth = self.contentWidth!=0.f?self.contentWidth:textSize.width;
- self.contentHeight = self.contentHeight!=0.f?self.contentHeight:textSize.height;
- }
https://developer.apple.com/library/ios/documentation/UIKit/Reference/NSString_UIKit_Additions/Reference/Reference.html#//apple_ref/occ/instm/NSString/boundingRectWithSize:options:attributes:context:

ios7新增的屬性sectionIndexBackgroundColor,在索引沒有被觸摸時默認是白色。
- if (IS_IOS_7) {
- self.playersTableView.sectionIndexBackgroundColor = [UIColor clearColor];
- }
在ios7 ipad中tabbar高度不是49
In iOS 7, a tab bar on iPad has a height of 56 points.