#import "ViewController.h"
//纯手工打造
@interface ViewController ()
@property (weak, nonatomic) UIButton *leftUpBtn;
@property (weak, nonatomic) UIButton *rightNextBtn;
@property (weak, nonatomic) UIImageView *imageShow;
@property (weak, nonatomic) UILabel *labNum1;
@property (weak, nonatomic) UILabel *LabChinese1;
@property (nonatomic, assign) int index;
@property (nonatomic, strong) NSArray *arrayStrAndShow;
@end
#define CHTIcon @"icon"
#define CHTDesc @"desc"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//创建一个左Button对象
UIButton *btnzuo = [[UIButton alloc] init];
//添加按钮
[self.view addSubview:btnzuo];
//给按钮设置宽高
btnzuo.frame = CGRectMake(29, 169, 30, 30);
//给按钮设置图片
UIImage *noImage = [UIImage imageNamed:@"left_normal"];
[btnzuo setBackgroundImage:noImage forState:UIControlStateNormal];
UIImage *hiImage = [UIImage imageNamed:@"left_highlighted"];
[btnzuo setBackgroundImage:hiImage forState:UIControlStateHighlighted];
self.leftUpBtn = btnzuo;
//创建一个右Button对象
UIButton *btnyou = [[UIButton alloc] init];
//添加按钮
[self.view addSubview:btnyou];
//给按钮设置宽高
btnyou.frame = CGRectMake(309, 169, 30, 30);
//给按钮设置图片
UIImage *noImage1 = [UIImage imageNamed:@"right_normal"];
[btnyou setBackgroundImage:noImage1 forState:UIControlStateNormal];
UIImage *hiImage1 = [UIImage imageNamed:@"right_highlighted"];
[btnyou setBackgroundImage:hiImage1 forState:UIControlStateHighlighted];
self.rightNextBtn = btnyou;
//创建UIImageView
UIImageView *imageview = [[UIImageView alloc] init];
//向view中添加iamgeview
[self.view addSubview:imageview];
//给iamgeview设置位置和宽高
imageview.frame = CGRectMake(96, 94, 180, 180);
imageview.image = [UIImage imageNamed:@"1"];
self.imageShow = imageview;
//创建俩个lable对象
UILabel *labNum = [[UILabel alloc] init];
//把lable添加到view中
[self.view addSubview:labNum];
labNum.frame = CGRectMake(96, 48, 180, 38);
labNum.text=@"2/5";
labNum.textAlignment = NSTextAlignmentCenter;
UILabel *labChinese = [[UILabel alloc] init];
self.labNum1 = labNum;
//把lable添加到view中
[self.view addSubview:labChinese];
labChinese.frame = CGRectMake(61, 320, 278, 76);
labChinese.text=@"有啥牛逼的";
labChinese.textAlignment = NSTextAlignmentCenter;
self.LabChinese1 = labChinese;
//给两个btn添加事件
[btnzuo addTarget:self action:@selector(btnLeft) forControlEvents:UIControlEventTouchUpInside];
[btnyou addTarget:self action:@selector(btnRight) forControlEvents:UIControlEventTouchUpInside];
NSBundle *bundle = [NSBundle mainBundle];
//获取DataImagePlist的全路径
NSString *path = [bundle pathForResource:@"DataImagePlist" ofType:@"plist"];
self.arrayStrAndShow = [NSArray arrayWithContentsOfFile:path];
self.index = -1;
[self btnRight];
}
- (void)changeData
{
//获取字典
NSDictionary *dic = self.arrayStrAndShow[self.index];
self.imageShow.image = [UIImage imageNamed:dic[CHTIcon]];
unsigned long count1 = self.arrayStrAndShow.count;
NSString *str = [NSString stringWithFormat:@"%d / %lu",self.index + 1, count1];
self.labNum1.text = str;
self.LabChinese1.text = dic[CHTDesc];
self.leftUpBtn.enabled = (self.index != 0);
self.rightNextBtn.enabled = (self.index != (count1 - 1));
}
- (void)btnLeft
{
self.index--;
[self changeData];
}
- (void)btnRight
{
self.index++;
[self changeData];
}
@end