遇到一个需求,读取LaunchImages中的图片作为一个VC的背景图,搜罗一圈没找到靠谱的解决方案。
下面的代码可以解决,暂时还没有遇到问题,只是感觉不太好。如果有更好的方案,请留言告知,在此先道一声感谢!
NSDictionary * infoPlist = [[NSBundle mainBundle] infoDictionary];
NSArray * arr = infoPlist[@"UILaunchImages"];
CGSize size = [UIScreen mainScreen].bounds.size;
NSString * key = [NSString stringWithFormat:@"{%.f, %.f}",size.width,size.height];
NSString * imgName = @"";
for (NSDictionary * dic in arr) {
if ([[dic objectForKey:@"UILaunchImageSize"] isEqualToString:key]) {
imgName = dic[@"UILaunchImageName"];
}
}
_bgImgV = [[UIImageView alloc] initWithFrame:self.view.bounds];
_bgImgV.image = [UIImage imageNamed:imgName];
[self.view addSubview:_bgImgV];