目前我是这样做的
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:
([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)?
@"Main_iPad" : @"Main_iPhone" bundle:nil];
但我很想像 UIImage 那样做:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
然后由 XCode
决定使用后缀查找的位置。
这可能吗?如果是这样怎么办?如果不是,为什么?
最佳答案
那些 _iPad 和 _iPhone 后缀是简单的标识符,可以在您创建新 Storyboard时更改为您喜欢的任何内容,它们与 @2x 内容(或图像 Assets )无关。 但是,如果你大量使用不同的 Storyboard(为了让它们的编辑更简单、更流畅,并且它们的版本控制合并更安全),你可以在 UIStoryboard 上写一个类别,然后用像这样的方法在一个地方写你自己的逻辑
+ (UIStoryboard*) appropriateStoryboardWithName:(NSString*) name bundle:(NSBundle*) bundle
{
name = [name stringByAppendingString:
([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) ? @"_iPad" : @"_iPhone"];
return [UIStoryboard storyboardWithName:name bundle:bundle];
}
关于ios - 无需代码即可切换 StoryBoards (iphone/iPad)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22518005/