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的更多相关文章
随机推荐
- iOS开发——UI篇Swift篇&UITextView
UITextView 一:UITextView使用及其属性的设置 titleLabel.text = titleString //创建UITextView对象 textView = UITextVie ...
- Docker 底层实现
基本架构 Docker 采用了 C/S架构,包括客户端和服务端. Docker daemon 作为服务端接受来自客户的请求,并处理这些请求(创建.运行.分发容器). 客户端和服务端既可以运行在一个机器 ...
- 集成支付宝钱包支付ios SDK的方法和经验
没想到,支付宝的SDK是我目前用过的所有第三方SDK中最难用的一个了. 下载 首先,你要想找到这个SDK,都得费点功夫.现在的SDK改名叫移动支付集成开发包了,下载页面在 这里 的 “请点此下载集成开 ...
- nginx +lua +redis 构建自动缓存系统
一. nginx环境搭建 第一步下载 LuaJIT-2.0.4.tar.gz http://luajit.org/download/LuaJIT-2.0.4.tar.gz安装 make &&a ...
- android系统启动时自动运行自己的程序
android系统在Manifest.permission中有这样一条RECEIVE_BOOT_COMPLETED的定义,当你自己的程序加 入这个权限后,就可以在系统启动完毕后收到一条系统的广播,这个 ...
- iOS 下拉刷新 上拉加载实现原理
1.下拉刷新 实现原理 if (scrollView.contentOffset.y < -100) { [UIView animateWithDuration:1.0 animations:^ ...
- 递归删除指定目录下的 .git 文件
转载自:http://my.oschina.net/armsky/blog/34447 find . -name .git | xargs rm -fr 其中对 xargs 的介绍,可以参照以下内容: ...
- Ubuntu14.04 搭建 node.js 环境(Binaries方式)
从官网下载 http://nodejs.org/download/ Linux Binaries (.tar.gz) 下载下来的是node-v0.10.29-linux-x64.tar.gz文件 解 ...
- spring事务管理出错。No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy ...
- [Android]天气App 3 网络数据的请求和Json解析
Android客户端开发,不仅仅是在Android端开发,还需要有相应的后台服务支持,否则的话,客户端的数据就只能放到本地自己做处理.我认为的原生态的App就是对应服务端的Client.他能像浏览 ...