图片浏览器
来源:互联网 发布:入骨相思知不知txt番外 编辑:程序博客网 时间:2024/05/15 23:45
效果图
纯代码编写:
//
// ViewController.h
// 图片浏览器-1
//
// Created by Mac on 15-9-19.
// Copyright (c) 2015年 Mac. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController :UIViewController
@property (nonatomic,strong)UILabel *titleLable;//标题
@property (nonatomic,strong)UIImageView *imageView;//图片
@property (nonatomic,strong)UIButton *leftButton;//左按钮
@property (nonatomic,strong)UIButton *rightButton;//右按钮
@property (nonatomic,strong)NSArray *arr;
@end
.m文件
//
// ViewController.m
// 图片浏览器-1
//
// Created by Mac on 15-9-19.
// Copyright (c) 2015年 Mac. All rights reserved.
//
#import "ViewController.h"
#define kScreenW [UIScreen mainScreen].bounds.size.width
@interface ViewController ()
@property (nonatomic,assign)int index;//索引值
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
[selfloadData];
[selftitleLableInfomation];
[selfpicture];
[selfbutton];
//默认显示数据
self.index= -1;
self.index++;
[selfsetData];
}
- (void)loadData{
//读取数据源
self.arr = [[NSArrayalloc] initWithContentsOfFile:[[NSBundlemainBundle] pathForResource:@"imageData.plist"ofType:nil]];
}
//标题显示
- (void)titleLableInfomation{
self.titleLable = [[UILabelalloc] initWithFrame:CGRectMake(kScreenW/2 -20,80 ,40, 40)];
[self.viewaddSubview:self.titleLable];
}
//显示图片
- (void)picture{
self.imageView = [[UIImageViewalloc] initWithFrame:CGRectMake(kScreenW/2 -100, 130,200 ,200)];
[self.viewaddSubview:self.imageView];
}
- (void)button{
//左边按钮
self.leftButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
self.leftButton.frame =CGRectMake(15,200, 40, 40);
[self.leftButtonsetImage:[UIImageimageNamed:@"left_highlighted"]forState:UIControlStateNormal];
[self.viewaddSubview:self.leftButton];
[self.leftButtonaddTarget:selfaction:@selector(leftAction)forControlEvents:UIControlEventTouchUpInside];
//右边按钮
self.rightButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
self.rightButton.frame =CGRectMake(315,200, 40, 40);
[self.rightButtonsetImage:[UIImageimageNamed:@"right_highlighted"]forState:UIControlStateNormal];
[self.viewaddSubview:self.rightButton];
[self.rightButtonaddTarget:selfaction:@selector(rightAction)forControlEvents:UIControlEventTouchUpInside];
}
//事件响应
- (void)rightAction{
self.index++;
//调用数据
[selfsetData];
}
- (void)leftAction{
self.index--;
[selfsetData];
}
//设置数据
- (void)setData{
//设置数据源
self.titleLable.text = [NSStringstringWithFormat:@"%d/%ld",self.index,self.arr.count];
NSDictionary *dic = _arr[self.index];
self.imageView.image =[UIImageimageNamed:dic[@"icon"]];
self.leftButton.enabled = (self.index !=0);
self.rightButton.enabled = (self.index !=self.arr.count -1);
}
- 图片浏览器
- 图片浏览器
- 图片浏览器
- 图片浏览器
- 图片浏览器
- 图片浏览器
- 图片浏览器
- 图片浏览器
- 图片浏览器
- 图片浏览器
- 小巧工具--图片浏览器
- 用浏览器浏览图片
- VB制作图片浏览器
- js 图片切换浏览器
- [VB.NET]图片浏览器
- 手机浏览器图片显示
- 简单的图片浏览器
- Js图片浏览器
- 动画xml
- Java中的继承和多态
- cvc-elt.1: Cannot find the declaration of element 'beans'.
- NetBeans IDE 8.0应用
- sql 防注入漏洞
- 图片浏览器
- 指针函数与函数指针的区别
- leetcode - Move Zeroes
- python idle 清屏
- usaco shopping offers 解析 and C 语言实现
- 使用oracle数据库需要注意的问题
- shape:画圆角
- webdriver环境搭建
- 函数指针及其的运用(上)——何为函数指针