码迷,mamicode.com
首页 > 移动开发 > 详细

IOS开发之图片浏览

时间:2015-08-21 11:22:58      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:ios   界面   ios开发   图片   imageview   

这是整体的效果图:

技术分享

其中main.stroyboard中的控件有2个button,2个label,一个imageView。
设置他们的位置大小和背景颜色和图片。
让main.storyboard连接ViewController.m

下面是它的代码:

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *topLabel;
@property (weak, nonatomic) IBOutlet UILabel *descLabel;
@property (weak, nonatomic) IBOutlet UIButton *leftBtn;
@property (weak, nonatomic) IBOutlet UIButton *rightBtn;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@property (nonatomic, assign) int index;

@property (nonatomic, strong) NSArray *imageDicts;

@end

@implementation ViewController

- (NSArray *)imageDicts
{
    if (!_imageDicts) {

        NSString *path = [[NSBundle mainBundle] pathForResource:@"imageDate.plist" ofType:nil];
        _imageDicts = [NSArray arrayWithContentsOfFile:path];
    }
    return _imageDicts;
}



- (IBAction)leftBtnOnClick:(UIButton *)sender {
    self.index --;

    [self btnClickChange];

}
- (IBAction)rightBtnOnClick:(id)sender {
    self.index ++;

    [self btnClickChange];
}

- (void)btnClickChange
{
    self.topLabel.text = [NSString stringWithFormat:@"%d/%d", (self.index + 1), self.imageDicts.count];


    self.descLabel.text = self.imageDicts[self.index][@"description"];

    self.imageView.image = [UIImage imageNamed:self.imageDicts[self.index][@"name"]];

    self.leftBtn.enabled = (self.index != 0);
    self.rightBtn.enabled = (self.index != 4);
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

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

@end

这样就完成了一个简单的图片浏览的应用。

版权声明:本文为博主原创文章,未经博主允许不得转载。

IOS开发之图片浏览

标签:ios   界面   ios开发   图片   imageview   

原文地址:http://blog.csdn.net/quzhiyu_rjgcs/article/details/47831065

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!