你可以試試這個 在頭部,你可以定義宏不同的設備,如
#define IS_IPHONE_5 (fabs((double)[ [ UIScreen mainScreen ] bounds ].size.height - (double)568) < DBL_EPSILON)
#define IS_IPHONE_6 (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)667) < DBL_EPSILON)
#define IS_IPHONE_6_PLUS (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)736) < DBL_EPSILON)
然後if和else條件的..
UIImageView *imageview;
if (IS_IPHONE_5){
imageview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 45)];
imageview.image=[UIImage imageNamed:@"yourimage" ];
[self.navigationController.navigationBar addSubview:imageview];}
else if(IS_IPHONE_6){
imageview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 375, 55)];
imageview.image=[UIImage imageNamed:@"select_albums6"];
}else if (IS_IPHONE_6_PLUS){
imageview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 414, 55)];
imageview.image=[UIImage imageNamed:@"select_albums6"];
} else
{
// 3.5 inch
imageview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 45)];
imageview.image=[UIImage imageNamed:@"select_album"];
}
,然後添加導航子視圖
[self.navigationController.navigationBar addSubview:imageview];
注意:這個代碼寫在ViewDidLoad和ViewWillAppear方法,所以導航欄設置爲您的自定義尺寸... 我希望這會幫助
您也應該檢查其iPhone或iPad的成語,比如: '#定義IS_IPHONE(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone)' – Laszlo 2014-10-17 12:56:23
@Tuss你是對的 – 2014-10-17 12:58:20