UI基础-04图片浏览器

来源:互联网 发布:阿里云医疗 编辑:程序博客网 时间:2024/06/11 03:30
<pre name="code" class="objc">////  ViewController.m//  UI基础-04图片浏览器////  Created by  NorthCity on 15/9/7.//  Copyright (c) 2015年 Tcg. All rights reserved.//#import "ViewController.h"@interface ViewController ()@property (weak, nonatomic) IBOutlet UILabel *indexLabel;@property (weak, nonatomic) IBOutlet UIImageView *imageView;@property (weak, nonatomic) IBOutlet UIButton *leftButton;@property (weak, nonatomic) IBOutlet UIButton *rightButton;@property (weak, nonatomic) IBOutlet UILabel *infoLabel;//数组保存图片信息和图片名字的字典@property(strong,nonatomic) NSArray *imageData;//index用来指示第几张图片@property(nonatomic,assign) int index;@end@implementation ViewController- (void)viewDidLoad {    self.index = 0;    [self reloadView];    }//这里重写数组的get方法,好处随用随取-(NSArray*)imageData{    if (_imageData == nil) {        //        注意这里用可变字典啊        NSMutableDictionary *imge0 =[NSMutableDictionary dictionary];        imge0[@"icon"] = @"biaoqingdi";        imge0[@"info"] = @"在他面前,其他神马表情都弱爆了!";                NSMutableDictionary *imge1 =[NSMutableDictionary dictionary];        imge1[@"icon"] = @"wangba";        imge1[@"info"] = @"哥们为什么选八号呢";                        NSMutableDictionary *imge2 =[NSMutableDictionary dictionary];        imge2[@"icon"] = @"bingli";        imge2[@"info"] = @"这也忒狠了";                        NSMutableDictionary *imge3 =[NSMutableDictionary dictionary];        imge3[@"icon"] = @"chiniupa";        imge3[@"info"] = @"这小姑娘吃个牛排比杀牛还费劲啊";                        NSMutableDictionary *imge4 =[NSMutableDictionary dictionary];        imge4[@"icon"] = @"danteng";        imge4[@"info"] = @"亲,你能改下你的网名么?哈哈";                        _imageData = @[imge0,imge1,imge2,imge3,imge4];            }    return  _imageData;}-(void)reloadView{    self.indexLabel.text =[ NSString stringWithFormat:@"%d/%lu",self.index+1,(unsigned long)self.imageData.count];        self.imageView.image = [UIImage imageNamed:self.imageData[self.index][@"icon"]];    self.infoLabel.text = self.imageData[self.index][@"info"];    [self changeButtonState];}- (IBAction)clickLeftButton:(UIButton *)sender {    self.index--;    [self reloadView];}- (IBAction)clickRightButton:(UIButton *)sender {    self.index++;    [self reloadView];        }-(void)changeButtonState{    self.leftButton.enabled = self.index >0;    self.rightButton.enabled = self.index <4;}@end

2



0 0
原创粉丝点击