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;