IOS之从plist文件中获取数据
2017-04-01 02:42
260 查看
1.定义数组
NSMutableArray *_foodArray;
2.从文件中读取plist文件路径(foodData是你plist文件的名字)
NSString *foodPlistPath =[[NSBundle
mainBundle] pathForResource:@"foodData"
ofType:@"plist"];
3.初始化数组
_foodArray = [[NSMutableArray
alloc] initWithContentsOfFile:foodPlistPath];
4.获取plist文件数据(image,newPrice,oldPrice为plist文件中的key)
NSString *imageName = [foodArray[i]
objectForKey:@"image"];
NSNumber *newPrice = [foodArray[i]
objectForKey:@"newPrice"];
NSNumber *oldPrice = [foodArray[i]
objectForKey:@"oldPrice"];
5.通过tag获取相关控件的一些属性
UIImageView *imageView = (UIImageView *)[self
viewWithTag:20+i];
6.对imageView相关属性赋值
imageView.image = [UIImage
imageNamed:imageName];
UILabel *newPriceLabel = (UILabel *)[self
viewWithTag:50+i];
newPriceLabel.text = [NSString
stringWithFormat:@"%@元",newPrice];
UILabel *oldPriceLabel = (UILabel *)[self
viewWithTag:70+i];
NSString *oldStr = [NSString
stringWithFormat:@"%@元",oldPrice];
//在oldPrice的数据上设置中划线
NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber
numberWithInteger:NSUnderlineStyleSingle]};
NSMutableAttributedString *attribtStr = [[NSMutableAttributedString
alloc]initWithString:oldStr
attributes:attribtDic];
oldPriceLabel.attributedText = attribtStr;
NSMutableArray *_foodArray;
2.从文件中读取plist文件路径(foodData是你plist文件的名字)
NSString *foodPlistPath =[[NSBundle
mainBundle] pathForResource:@"foodData"
ofType:@"plist"];
3.初始化数组
_foodArray = [[NSMutableArray
alloc] initWithContentsOfFile:foodPlistPath];
4.获取plist文件数据(image,newPrice,oldPrice为plist文件中的key)
NSString *imageName = [foodArray[i]
objectForKey:@"image"];
NSNumber *newPrice = [foodArray[i]
objectForKey:@"newPrice"];
NSNumber *oldPrice = [foodArray[i]
objectForKey:@"oldPrice"];
5.通过tag获取相关控件的一些属性
UIImageView *imageView = (UIImageView *)[self
viewWithTag:20+i];
6.对imageView相关属性赋值
imageView.image = [UIImage
imageNamed:imageName];
UILabel *newPriceLabel = (UILabel *)[self
viewWithTag:50+i];
newPriceLabel.text = [NSString
stringWithFormat:@"%@元",newPrice];
UILabel *oldPriceLabel = (UILabel *)[self
viewWithTag:70+i];
NSString *oldStr = [NSString
stringWithFormat:@"%@元",oldPrice];
//在oldPrice的数据上设置中划线
NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber
numberWithInteger:NSUnderlineStyleSingle]};
NSMutableAttributedString *attribtStr = [[NSMutableAttributedString
alloc]initWithString:oldStr
attributes:attribtDic];
oldPriceLabel.attributedText = attribtStr;
相关文章推荐
- IOS 获取.plist文件的数据
- ios开发从.plist文件中获取数据
- IOS学习笔记之获取Plist文件读取数据
- iOS-从plist文件获取数据
- Objc将数据写入iOS真机的plist文件中
- iOS 代码中获取info.plist文件对应的字典对象
- Objc将数据写入iOS真机的plist文件中
- iOS获取相册视频文件封面图 选取手机中的音频、视频文件并导出数据。
- OC从plist文件中获取数据
- 【iOS开发-74】解决方案:Xcode6下利用preference保存数据,最终的plist文件在哪里?
- Objc将数据写入iOS真机的plist文件中
- iOS——写数据到本地plist文件
- iOS应用程序安全(20)-本地数据存储及其安全性(NSUserDefaults, Keychain,CoreData, Sqlite, Plist 文件)
- IOS 004 数据的加载方式 懒加载 以及plist文件的读取
- Plist 文件的多次读写,实现IOS数据的本地化处理,实现小量数据的本地化处理
- iOS应用程序安全(20)-本地数据存储及其安全性(NSUserDefaults, CoreData, Sqlite, Plist 文件)
- IOS获取plist文件属性值的方法
- cocos2dx-深度解析plist文件(一)(游戏对象的数据如何从plist创建获取)
- iOS获取plist文件属性值的方法
- IOS获取plist文件信息