您的位置:首页 > 编程语言

图片浏览器代码

2015-08-16 09:36 330 查看
//
//  ViewController.m
//  photoexplorer_test1
//
//  Created by administrator on 15/8/4.
//  Copyright (c) 2015年 gengcong. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet UILabel *descLabel;
- (IBAction)leftClick:(id)sender;
@property (weak, nonatomic) IBOutlet UIButton *leftBtn;
- (IBAction)rightClick:(id)sender;
@property (weak, nonatomic) IBOutlet UIButton *rightBtn;
@property(nonatomic,strong)NSArray *imageData;
@property(nonatomic,assign)int index;
@property (weak, nonatomic) IBOutlet UIImageView *photoView;
@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.index=0;
[self changePhoto];
if (_imageData==nil) {
NSBundle *bundle=[NSBundle mainBundle];
NSString *path=[bundle pathForResource:@"photo" ofType:@"plist"];
_imageData=[NSArray arrayWithContentsOfFile:path];
}
self.contentLabel.text=[NSString stringWithFormat:@"%d/%lu",self.index+1,(unsigned long)self.imageData.count];
NSDictionary *dic=self.imageData[self.index];
NSString *name=dic[@"icon"];
NSString *desc=dic[@"desc"];
self.photoView.image=[UIImage imageNamed:name];
self.descLabel.text=desc;
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

-(void)changePhoto
{
self.contentLabel.text=[NSString stringWithFormat:@"%d/%lu",self.index+1,(unsigned long)self.imageData.count];
NSDictionary *dic=self.imageData[self.index];
//    NSString *name=dic[@"icon"];
NSString *desc=dic[@"desc"];
self.photoView.image=[UIImage imageNamed:[NSString stringWithFormat:@"%d",self.index+1]];
self.descLabel.text=desc;
BOOL Isfirst=NO;
BOOL Islast=NO;
if (self.index==0) {
Isfirst=YES;
}
if (self.index==self.imageData.count-1) {
Islast=YES;
}
if (Isfirst) {
self.leftBtn.enabled=NO;
}
else self.leftBtn.enabled=YES;
if (Islast) {
self.rightBtn.enabled=NO;

}
else self.rightBtn.enabled=YES;

}

- (IBAction)leftClick:(id)sender {
self.index--;
[self changePhoto];

}
- (IBAction)rightClick:(id)sender {
self.index++;
[self changePhoto];
}
@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: