我目前正在使用 UAModalPanel,我只想用这个组件显示图片。所以我做了以下事情:
#import <UIKit/UIKit.h>
#import "UAModalPanel.h"
@interface LolcatPanel : UAModalPanel
- (void)showLolcat;
@end
#import "LolcatPanel.h"
@implementation LolcatPanel
- (void)showLolcat
{
int pic = (arc4random() % 10) + 1;
NSString *intString = [NSString stringWithFormat:@"%d", pic];
NSMutableString *picture = [[NSMutableString alloc] initWithString:intString];
[picture appendString:@".jpg"];
NSLog(@"Loading image %@", picture);
NSString* imageName = [[NSBundle mainBundle] pathForResource:intString ofType:@"jpg"];
UIImage *testImage = [UIImage imageWithContentsOfFile:imageName];
if (testImage == nil) {
NSLog(@"FAILED");
}
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)];
imgView.image = testImage;
imgView.contentMode = UIViewContentModeScaleToFill;
[self addSubview:imgView];
}
@end
我想在 UAModelPanel 中显示适合的图片,但 ATM 的结果并不是很好。