画册视图,控制图片移动
//
// ViewController.m
// ios20141222
//
// Created by fulin on 14/12/22.
// Copyright (c) 2014年 fulin. All rights reserved.
//
/**
当map中建和值确定时候,我们采取宏,定义全局
*/
#define FLIconKey @"icon"
#import "ViewController.h"
@interface ViewController ()
/**
一个结论:
strong用于一般数据
weak用于控件
*/
@property (weak, nonatomic) IBOutlet UILabel *number;
@property (weak, nonatomic) IBOutlet UIImageView *showImage;
@property (weak, nonatomic) IBOutlet UILabel *descripitionMessage;
@property (weak, nonatomic) IBOutlet UIButton *previousBtn;
@property (weak, nonatomic) IBOutlet UIButton *nextBtn;
@property (nonatomic, assign) int index;//记录当前显示是第几张图片
//@property (nonatomic, strong) NSString numbers[5] = {"SB1","SB2","SB3","SB4","SB5"};
@property (nonatomic, strong) NSArray *imgDataArrays;
- (IBAction)previous;
- (IBAction)next;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
//初始化
NSMutableDictionary *img1 = [NSMutableDictionary dictionary];
img1[FLIconKey] = @"1";
NSMutableDictionary *img2 = [NSMutableDictionary dictionary];
img2[FLIconKey] = @"2";
NSMutableDictionary *img3 = [NSMutableDictionary dictionary];
img3[FLIconKey] = @"3";
NSMutableDictionary *img4 = [NSMutableDictionary dictionary];
img4[FLIconKey] = @"4";
NSMutableDictionary *img5 = [NSMutableDictionary dictionary];
img5[FLIconKey] = @"5";
self.imgDataArrays = @[img1, img2, img3, img4, img5];
self.number.text = @"1/5";
self.showImage.image = [UIImage imageNamed:@"1"];
self.index = -1;
[self next];
}
#pragma mark 上一张
- (IBAction)previous{
self.index = self.index == 0 ? 0 : --self.index;
[self changeData];
}
#pragma mark 下一张
- (IBAction)next
{
self.index = self.index == 4 ? 4 : ++self.index;
[self changeData];
}
#pragma mark 改变的方法
- (void)changeData
{
self.previousBtn.enabled = self.index != 0;//设置按钮能否可用
self.nextBtn.enabled = self.index != 4;
self.number.text = [NSString stringWithFormat:@"%d/%d",self.index+1,5];
NSDictionary *imageDict = self.imgDataArrays[self.index];
self.showImage.image = [UIImage imageNamed:imageDict[FLIconKey]];
}
@end
简单画册案例,画册视图,控制图片移动
最新推荐文章于 2015-10-10 14:46:48 发布