代码中自己用的模版之一

为了方便自己,在写代码时要用到的出示类

#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);
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值