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的更多相关文章
随机推荐
- 【JavaScript】JavaScript中的陷阱大集合
本文主要介绍怪异的Javascript,毋庸置疑,它绝对有怪异的一面.当软件开发者开始使用世界上使用最广泛的语言编写代码时,他们会在这个过 程中发现很多有趣的“特性”.即便是老练的Javascript ...
- 【JavaScript】javascript常用的东西
DOM编程.AJAX编程.异步编程(nodejs会涉及的相对多一点,事件.ajax) 函数.函数表达式.回调函数是基础. JavaScript的函数是一个核心. 回调函数有点类似于Android中的回 ...
- [Angular2 Form] Create Radio Buttons for Angular 2 Forms
Using Radio Buttons in Angular 2 requires a basic understanding of forms as well as how their labels ...
- [MEAN Stack] First API -- 3. Select by ID with Mongoose and Express
Mongoose allows you to easily select resources by ID from your MongoDB. This is an important aspect ...
- xcode中没有autoSizing的设置
转自:http://blog.sina.com.cn/s/blog_954bb2f001016oyx.html 学习Xcode的iOS编程时,可能会发现Autosizing Control不见了,其原 ...
- tomcat7.0建立新的web服务目录
今天参照网上的配置方法配置了下tomcat的web服务目录,结果总是显示404错误,错误原因是The requested resource is not available.搜索了半天解决方法,终于发 ...
- 对lua继承中self.__index = self的释疑
首先看看从lua表中查找一个键时的流程: -- 当从表t中查找键k时,lua处理如下: -- 1.t中是否有k,有则直接返回值,否则第2步 -- 2.t是否有元表, 无则返回nil, 有则第3步 -- ...
- 1.5.6 Filters
Filters 过滤器filter应该跟在tokenizer或者另一个filter之后.因为它们将TokenStream作为输入源. <fieldType name="text&quo ...
- spring mvc 接收页面表单List
很少写博客,如果写的不好请多多包涵! 最近在用Spring mvc时遇到一个问题,在网上搜了很多资料.几乎没看到解决办法! 例如:当我们在做批量添加或者更新时,在Controller层接收表单数据的问 ...
- 用bootstrapValidator来验证UEditor
我们的项目使用了bootstrapValidator来作为前端校验,但是表单里面有一个UEditor,它用bootstrapValidator是没有效果的,为了页面风格统一,只好修修改改咯 首先来看一 ...