自己闲暇之余写的一个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