@implementation BEViewController
NSArray *_allDescs;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//定义图片描述供给其他方法使用
NSBundle *bundel = [NSBundle mainBundle];
NSString *path = [bundel pathForResource:@"imageDesc" ofType:@"plist"];
_allDescs = [NSArray arrayWithContentsOfFile:path];
_imageDesc.text = _allDescs[0];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)onChange:(UISlider *)sender {
//%.f 意思为只取得整数部分
NSString *imageName = [NSString stringWithFormat:@"%.f.png",sender.value];
//1. 改变图片的image
_images.image = [UIImage imageNamed:imageName];
//2. 改变图片的计数器
_imageNo.text = [NSString stringWithFormat:@"%.f/16",sender.value+1];
//3. 改变图片的描述
int nums = (int)(sender.value+0.5);
_imageDesc.text = _allDescs[nums];
}

下一篇:虐我--好玩按钮--代码实现