【IOS】一个完整的plist读取demo

自己闲暇之余写的一个plist读取demo,适合初学者...不足之处欢迎指正(附下载地址)


//
//  PlistDemoView.m
//  PlistDemo
//
//  Created by 东 王 on 12-3-25.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "PlistDemoView.h"

@implementation PlistDemoView
@synthesize imageDemo;

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    NSString *imagePath= [[NSBundle mainBundle] pathForResource:@"images" ofType:@"plist"];
    NSDictionary *imageDiction= [NSDictionary dictionaryWithContentsOfFile:imagePath];
    for (int i=1; i<=imageDiction.count; i++) {
        NSDictionary *dataFromPlist=[NSDictionary dictionaryWithDictionary:[imageDiction objectForKey:[NSString stringWithFormat:@"image%d",i]
                                                                            ]];
        
        NSString *stringPlist=[dataFromPlist objectForKey:@"imageDetail"];
        NSLog(@"imagePlist%@",stringPlist);
        
        NSString *imageName=[dataFromPlist objectForKey:@"imageName"];
        int imageLeftTopL=[[dataFromPlist objectForKey:@"leftTopL"] intValue];
        int imageLeftTopR=[[dataFromPlist objectForKey:@"leftTopR"] intValue];
        int imageWidth=[[dataFromPlist objectForKey:@"width"] intValue];
        int imageHeight=[[dataFromPlist objectForKey:@"height"] intValue];
        
        imageDemo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
        [imageDemo setFrame:CGRectMake(imageLeftTopL, imageLeftTopR, imageWidth, imageHeight)];
        
        [self.view addSubview:imageDemo];
    }
    
    
}



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
	return YES;
}

@end

demo下载地址: http://download.csdn.net/detail/dongge_111/4213235


  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值