你可以试试这个在标题中你可以为不同的设备定义宏,比如
#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 方法中编写,因此导航栏设置为您的自定义大小......我希望这会有所帮助