为了方便自己,在写代码时要用到的出示类
#pragma mark -初始化 - (id)init { self = [super init]; if (self) { } return self; } - (void)loadView{ [super loadView]; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } #pragma mark -内存管理 - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. } - (void)dealloc { [super dealloc]; } -(void)didReceiveMemoryWarning { /* This is the view controller's method */ [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. if(![self isViewLoaded]){ /* release your custom data which will be rebuilt in loadView or viewDidLoad */ } } #pragma mark -判断方向 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) { return YES; } else { return NO; } }加载图片的类:
#pragma mark -加载图片 -(UIImageView*)LoadResource:(NSString*)strName ext:(NSString*)strExt { // 加载欢迎的声音 NSString* strFileName = [[NSString alloc] initWithFormat:@"%@.%@",strName, strExt]; NSString* path; path = [[NSBundle mainBundle] pathForResource:strName ofType:strExt]; //判断是否存在这个文件 if (path == nil) { NSString *message = [NSString stringWithFormat:@"Can't find the resource %@", strFileName]; [self PrintLog:message]; if (strFileName) { [strFileName release]; strFileName = nil; return FALSE; } } //开始加载图片 UIImageView *imageView = nil; imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:path]]; NSString *message = [NSString stringWithFormat:@"Begin Load Resource %@!",strFileName]; [self PrintLog:message]; //判断是否加载完成 if (imageView == nil) { NSString *message = [NSString stringWithFormat:@"Load Resource %@ Failed!",strFileName]; [self PrintLog:message]; if (strFileName) { [strFileName release]; strFileName = nil; return FALSE; } } else { NSString *message = [NSString stringWithFormat:@"Load Resource %@ Success!",strFileName]; [self PrintLog:message]; } [strFileName release]; strFileName = nil; return imageView; } #pragma mark -输出日志 -(void) PrintLog:(NSString*)str { NSLog(@"%@",str); }