代码如下:
#import "ViewController.h" #define HMICON @"icon" #define HMINFO @"info"
typedef enum{kBack=1,kNext}kTag; @interface ViewController () @property(nonatomic,assign)int index; @property (weak, nonatomic) IBOutlet UILabel *pageLabel; @property (weak, nonatomic) IBOutlet UILabel *infoLabel; @property (weak, nonatomic) IBOutlet UIButton *backButton; @property (weak, nonatomic) IBOutlet UIButton *nextButton; @property (weak, nonatomic) IBOutlet UIImageView *iconImag; @property(nonatomic,strong)NSArray* imageArray;
@end
@implementation ViewController
- (void)viewDidLoad { [super viewDidLoad]; self.index = 0; //刷新图片 [self refreshImage]; }
- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }
//懒加载 -(NSArray *)imageArray { if (_imageArray==nil) { NSDictionary*image01 = @{HMICON:@"biaoqingdi",HMINFO:@"在他面前,其他神马表情都弱爆了!"}; NSDictionary*image02 = @{HMICON:@"wangba",HMINFO:@"哥们为什么选八号呢"}; NSDictionary*image03 = @{HMICON:@"bingli",HMINFO:@"这也忒狠了"}; NSDictionary*image04 = @{HMICON:@"chiniupa",HMINFO:@"这小姑娘吃个牛排比杀牛还费劲啊"}; NSDictionary*image05 = @{HMICON:@"danteng",HMINFO:@"亲,你能改下你的网名么?哈哈"}; NSDictionary*image06 = @{HMICON:@"1",HMINFO:@"新增1"}; NSDictionary*image07 = @{HMICON:@"3",HMINFO:@"3"}; _imageArray = @[image01,image02,image03,image04,image05,image06,image07];
}
return _imageArray; }
-(void)refreshImage { self.pageLabel.text = [NSString stringWithFormat:@"%d/%lu",self.index+1,self.imageArray.count]; self.infoLabel.text = self.imageArray[self.index][HMINFO]; self.iconImag.image = [UIImage imageNamed:self.imageArray[self.index][HMICON]];
self.backButton.enabled =(self.index!=0); self.nextButton.enabled =(self.index!=self.imageArray.count-1);
} - (IBAction)clickButtons:(UIButton *)sender { switch (sender.tag) { case kBack: self.index--; break; case kNext: self.index++; break; }
[self refreshImage];
}
@end
|