UI2_ScrollViewHomeWork
//
// AppDelegate.m
// UI2_ScrollViewHomeWork
//
// Created by zhangxueming on 15/7/13.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "AppDelegate.h"
#import "ViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
ViewController *root = [[ViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:root];
self.window.rootViewController = nav;
self.window.backgroundColor = [UIColor whiteColor];
//[self.window makeKeyAndVisible]; return YES;
} //
// ViewController.h
// UI2_ScrollViewHomeWork
//
// Created by zhangxueming on 15/7/13.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h>
#import "DetailViewController.h" @interface ViewController : UIViewController <sendMessageReport> @end
//
// ViewController.m
// UI2_ScrollViewHomeWork
//
// Created by zhangxueming on 15/7/13.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ViewController.h"
#import "CustomImageView.h"
#import "DetailViewController.h" @interface ViewController ()
{
UIScrollView *_scrollView;
} @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
self.automaticallyAdjustsScrollViewInsets = YES;
_scrollView.showsHorizontalScrollIndicator = NO;
_scrollView.showsVerticalScrollIndicator = NO;
_scrollView.bounces = NO;
//_scrollView.backgroundColor = [UIColor cyanColor];
NSInteger rowCount = 4;
CGFloat space = 2;
CGFloat imageViewWidth = (self.view.frame.size.width-2*5)/4;
CGFloat imageViewHeight = imageViewWidth*1.5; NSString *path = [[NSBundle mainBundle] pathForResource:@"AlbumData" ofType:@"plist"];
NSArray *array = [NSArray arrayWithContentsOfFile:path];
int i=0;
for (NSDictionary *dict in array) {
NSString *title = [dict objectForKey:@"TITLE"];
NSString *name = [NSString stringWithFormat:@"%@.jpg",[dict objectForKey:@"NAME"]];
UIImage *image = [UIImage imageNamed:name]; CustomImageView *imageView = [[CustomImageView alloc] initWithFrame:CGRectMake(space+(space+imageViewWidth)*(i%rowCount), (i/rowCount)*(space+imageViewHeight)+space, imageViewWidth, imageViewHeight)];
imageView.image = image;
imageView.label.text = title;
imageView.tag = 100+i; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)];
imageView.userInteractionEnabled = YES;
[imageView addGestureRecognizer:tap]; [_scrollView addSubview:imageView];
i++;
}
_scrollView.contentSize = CGSizeMake(self.view.frame.size.width, (imageViewHeight+space)*8+space);
[self.view addSubview:_scrollView];
} - (void)tapGesture:(UITapGestureRecognizer *)tap
{
DetailViewController *dvc = [[DetailViewController alloc] init];
dvc.image = ((UIImageView *)tap.view).image;
dvc.imageViewTag = tap.view.tag;
dvc.delegate = self; [self.navigationController pushViewController:dvc animated:YES];
} - (void)sendViewTag:(NSInteger)tag andTitle:(NSString *)title
{
CustomImageView *imageView = (CustomImageView *)[_scrollView viewWithTag:tag];
imageView.label.text = title;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
//
// CustomImageView.h
// UI2_ScrollViewHomeWork
//
// Created by zhangxueming on 15/7/13.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface CustomImageView : UIImageView @property (nonatomic,strong) UILabel *label;
@property (nonatomic,copy)NSString *title; @end //
// CustomImageView.m
// UI2_ScrollViewHomeWork
//
// Created by zhangxueming on 15/7/13.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "CustomImageView.h" @implementation CustomImageView /*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/ - (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 50)];
self.label.alpha = 0.5;
self.label.textAlignment = NSTextAlignmentCenter;
self.label.adjustsFontSizeToFitWidth = YES;
self.label.text = self.title;
self.label.backgroundColor = [UIColor whiteColor];
[self addSubview:self.label];
}
return self;
} @end
//
// DetailViewController.h
// UI2_ScrollViewHomeWork
//
// Created by zhangxueming on 15/7/13.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @protocol sendMessageReport <NSObject> - (void)sendViewTag:(NSInteger)tag andTitle:(NSString *)title; @end @interface DetailViewController : UIViewController @property (nonatomic, strong)UIImage *image;
@property (nonatomic, assign)NSInteger imageViewTag;
@property (nonatomic, assign)id <sendMessageReport > delegate; @end //
// DetailViewController.m
// UI2_ScrollViewHomeWork
//
// Created by zhangxueming on 15/7/13.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "DetailViewController.h" @interface DetailViewController () @end @implementation DetailViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 64, self.view.frame.size.width-20,50)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.tag = 200;
[self.view addSubview:textField]; UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 64+50, self.view.frame.size.width-20, 300)];
imageView.tag = 200;
imageView.image = self.image;
[self.view addSubview:imageView]; UIBarButtonItem *item= [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(btnClick)];
self.navigationItem.rightBarButtonItem = item;
} - (void)btnClick
{
UITextField *textField = (UITextField *)[self.view viewWithTag:200]; if ([_delegate respondsToSelector:@selector(sendViewTag:andTitle:)]) {
[_delegate sendViewTag:self.imageViewTag andTitle:textField.text];
}
[self.navigationController popViewControllerAnimated:YES];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
UI2_ScrollViewHomeWork的更多相关文章
随机推荐
- android startActivityForResult的用法
有时候我们需要把A activity提交数据给B activity处理,然后把结果返回给A 这种方式在很多种情况需要用到,比如我应用的程序需要有拍照上传的功能. 一种解决方案是 我的应用程序 〉调 ...
- 提高HTML5 canvas性能的几种方法
简介 HTML5 canvas 最初起源于苹果(Apple)的一项实验,现在已经成为了web中受到广泛支持的2D快速模式绘图(2Dimmediate mode graphic)的标准.许多开发者现在利 ...
- Perl 内部结构详解
PerlGuts Illustrated Version 0.49, for perl 5.20 and older This document is meant to supplement the ...
- ubantu 安装mysql
sudo apt-get install mysql-server mysql-client
- Java再学习——CopyOnWrite容器
一,定义 CopyOnWrite容器即写时复制的容器.通俗的理解是当我们往一个容器添加元素的时候,不直接往当前容器添加,而是先将当前容器进行Copy,复制出一个新的容器,然后新的容器里添加元素,添加完 ...
- 小白日记44:kali渗透测试之Web渗透-SqlMap自动注入(二)-sqlmap参数详解REQUEST
Sqlmap自动注入(二) Request ################################################### #inurl:.php?id= 1. 数据段:--d ...
- Using ASP.Net WebAPI with Web Forms
Asp.Net WebAPI is a framework for building RESTful HTTP services which can be used across a wide ran ...
- oc中的block使用心得
typedef void (^ simpleBlock) (void); typedef double (^multiplyTwoValues)(double, double); typedef vo ...
- nodejs的mysql模块学习(六)连接池的创建和使用
介绍 在 软件工程 , 连接池 是一个 高速缓存 的 数据库连接 维持,使得连接可以当需要将来向数据库请求重复使用. [ 来源请求 ] 连接池用于提高数据库上执行命令的性能. 打开并保持每个用户的数据 ...
- Java基础知识强化之IO流笔记72:NIO之 NIO核心组件(NIO使用代码示例)
1.Java NIO 由以下几个核心部分组成: Channels(通道) Buffers(缓冲区) Selectors(选择器) 虽然Java NIO 中除此之外还有很多类和组件,Channel,Bu ...