我像这样构建了自己的自定义 ImageView 类:
// UICustomImageView.h
@interface UICustomImageView : UIImageView
@property (nonatomic) NSString *filename568;
@end
// UICustomImageView.m
#import "UICustomImageView.h"
@implementation UICustomImageView
- (void)awakeFromNib {
[super awakeFromNib];
[self checkFor568];
}
-(void)drawRect:(CGRect)rect {
[super drawRect:rect];
[self checkFor568];
}
-(void)checkFor568 {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
if(screenSize.height == 568) {
if (self.filename568 != nil)
self.image = [UIImage imageNamed:self.filename568];
}
}
}
@end
像这样在 Interface Builder 中使用它。(仍将图像命名为 Background-568h@2x.png 进行缩放):