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图片适配,drawable文件夹,低分辨率图片是否必要
我们知道,Android提供了几种不同分辨率的bitmap,来对应不同手机屏幕的密度.对应关系如下: xxhdpi:3.0 xhdpi: 2.0 hdpi: 1.5 mdpi: 1.0 ldpi: 0 ...
- android 系统定制的小技巧(网络收集)
1开机图片: android-logo-mask.png android-logo-shine.png 这两个图片一个在上一个在下 ./out/target/common/obj/JAVA_LIBRA ...
- iOS开发——UI篇Swift篇&UIDatePicker
UIDatePicker //返回按钮事件 @IBAction func backButtonClick() { self.navigationController?.popViewControlle ...
- 生成html的几种方案
方案1: /// <summary > /// 传入URL返回网页的html代码 /// </summary > /// <param name=&q ...
- Android开发目录
1.ADT下载地址整理 2.之前的Android项目报错,新建Android项目报错,代码中找不到错误解决方案 3.错误“Unexpected namespace prefix "xmlns ...
- git无法连接bitbucket/github时,出现"Permission deied(publickey)"
Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you ha ...
- 【如何快速的开发一个完整的 iOS 直播 app】(美颜篇)
来源:袁峥Seemygo 链接:http://www.jianshu.com/p/4646894245ba 前言 在看这篇之前,如果您还不了解直播原理,请查看这篇文章如何快速的开发一个完整的iOS直播 ...
- web开发下的各种下载方法
利用TransmitFile方法,解决Response.BinaryWrite下载超过400mb的文件时导致Aspnet_wp.exe进程回收而无法成功下载的问题. 代码如下: Response.Co ...
- PetaPoco使用要点
PetaPoco是一款适用于.Net 和Mono的微小.快速.单文件的微型ORM! 可以从这里获得PetaPoco: NuGet - http://nuget.org/List/Packages/Pe ...
- Android 高级UI设计笔记21:Android SegmentView(分段选择控件)
1. 分段控制(SegmentView) 首先我们先看看什么是SegmentView的效果,如下: 分段控制这个View控件是ios7的分段控制,和QQ消息页面顶部的效果一样,android没有这个控 ...