//
// 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的更多相关文章

随机推荐

  1. 50个Android开发人员必备UI效果源码[转载]

    50个Android开发人员必备UI效果源码[转载] http://blog.csdn.net/qq1059458376/article/details/8145497 Android 仿微信之主页面 ...

  2. android获取/更改gps和WIFI状态

    一.WIFI状态的获取和更改 适用于 SDK1.0 , SDK1.5 1.获取WIFI状态 方法1:通过WifiManager进行操作 1WifiManager wifiManager = (Wifi ...

  3. EJB究竟是什么,真的那么神奇吗??

    1. 我们不禁要问,什么是"服务集群"?什么是"企业级开发"? 既然说了EJB 是为了"服务集群"和"企业级开发",那么 ...

  4. iPhone重绘机制drawRect

    如何使用iPhone进行绘图.重绘操作iPhone的绘图操作是在UIView类的drawRect方法中完成的,所以如果我们要想在一个UIView中绘图,需要写一个扩展UIView 的类,并重写draw ...

  5. php连接数据库时候的字符集设置

    最好的办法:设置mysql服务器的字符集,当然也可以通过mysql提供的api来设置运行时的字符集 Ideally a proper character set will be set at the ...

  6. windows和linux中检查端口是否被占用

    一.windows 1.查询端口占用情况 cmd > netstat -ano 2.查询8080端口是否被占用 cmd > netstat -ano|findstr 8080 3.查询哪个 ...

  7. Jquery zTree结合Asp.net实现异步加载数据

    zTree结合Asp.net实现异步加载数据 实现简单操作 zTree 下载 api 访问 :http://www.ztree.me/v3/main.php 例子中用到json数据转化 newtons ...

  8. PathAnimation

    使用Blend制作PathAnimation 1:选中Path转换为运动路径 2:选择目标对象 PathAnimation使用动态的Path PathAnimation动画在播放的时候,PahtGeo ...

  9. AsyncTask的介绍

    android AsyncTask介绍 AsyncTask和Handler对比 1 ) AsyncTask实现的原理,和适用的优缺点 AsyncTask,是android提供的轻量级的异步类,可以直接 ...

  10. Android&iOS崩溃堆栈上报

    Android&iOS崩溃堆栈上报 原文地址:http://www.cnblogs.com/songcf/p/4885468.html 通过崩溃捕获和收集,可以收集到已发布应用(游戏)的异常, ...