图片编辑器

来源:互联网 发布:大数据下的中国 编辑:程序博客网 时间:2024/06/07 00:15

//
// 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

0 0