3.5 インチと 4 インチのディスプレイ用に 2 つの別々の nib ファイルを提供する方がよいと思います。はい、これによりあなたの努力が増えることはわかっていますが、コードは将来的により管理しやすくなります。別のペン先を用意するだけです。
次のメソッドを使用して、必要な寸法のたびに nib を動的にロードできます。
-(void)pushViewController:(UIViewController*)viewController withNib:(NSString*)nibName
{
if(nibName){
nibName=[self getNibNameForNib:nibName];
viewController=[viewController initWithNibName:nibName bundle:nil];
[self.navigationController pushViewController:viewController animated:YES];
}
}
-(NSString*)getNibNameForNib:(NSString *)nibName
{
NSString *newNibName=nil;
if([self isIphone5Retina4InchDisplay]){
newNibName=[nibName stringByAppendingString:@"-568h"];
}
if(newNibName && [[NSBundle mainBundle] pathForResource:newNibName ofType:@"nib"] != nil)
{
//if iphone 5 and nib is also present for that resolution.
nibName=newNibName;
}
return nibName;
}
/**
Method to get if device is 4 inch iphone 5 retina device or not.
*/
-(BOOL)isIphone5Retina4InchDisplay
{
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
// code for 4-inch screen
return YES;
} else {
// code for 3.5-inch screen
return NO;
}
}
RETINA 4 インチ NIB の名前を LoginViewController-568h.xib として、-568h サフィックスを追加します。毎回この pushViewController メソッドを使用して、新しいビュー コントローラーをプッシュします。このメソッドは、Base ビュー コントローラーに記述できます。