iOS UI_相册
2015-08-10 08:45
661 查看
// // MainViewController.m // 相册 // // Created by dllo on 15/8/6. // Copyright (c) 2015年 zhozhicheng. All rights reserved. // #import "MainViewController.h" #import "SecondViewController.h" @interface MainViewController () //建立一个数组,存放图片 @property(nonatomic,retain)NSMutableArray *arr; @end @implementation MainViewController -(void)dealloc { [_arr release]; [super dealloc]; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //相册的目录界面,先改成不透明 self.navigationController.navigationBar.translucent=NO; self.view.backgroundColor=[UIColor orangeColor]; //设置标题 self.navigationItem.title=@"相册"; //初始化数组 self.arr = [[NSMutableArray alloc] init]; //七张视图 for (int i = 1; i < 8; i++) { NSString *imageName=[NSString stringWithFormat:@"h%d.jpeg",i]; UIImage *image=[UIImage imageNamed:imageName]; [self.arr addObject:image]; } //建立七个button for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (3 * i + j < 7) { UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.tag=3 * i + j +1; button.frame=CGRectMake(j * 120 + 20, i * 120 + 100, 100, 100); [self.view addSubview:button]; button.layer.borderWidth=1; //把图片放到对应的button [button setImage:(UIImage *)self.arr[3 * i + j] forState:UIControlStateNormal]; [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside]; } } } } -(void)click:(UIButton *)button { //点击跳到下一页 SecondViewController *secVC=[[SecondViewController alloc] init]; [self.navigationController pushViewController:secVC animated:YES]; [secVC release]; //传一个number值 secVC.number=button.tag - 1; } - (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
// // SecondViewController.h // 相册 // // Created by dllo on 15/8/6. // Copyright (c) 2015年 zhozhicheng. All rights reserved. // #import <UIKit/UIKit.h> @interface SecondViewController : UIViewController @property(nonatomic,assign)NSInteger number; @end
// // SecondViewController.m // 相册 // // Created by dllo on 15/8/6. // Copyright (c) 2015年 zhozhicheng. All rights reserved. // #import "SecondViewController.h" //定义两个宏,宽'高 #define WIDTH self.view.frame.size.width #define HEIGHT self.view.frame.size.height @interface SecondViewController ()<UIScrollViewDelegate> @property(nonatomic,retain)UIScrollView *scrollView; @end @implementation SecondViewController -(void)dealloc { [_scrollView release]; [super dealloc]; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //创建滚动页面 self.scrollView=[[UIScrollView alloc] initWithFrame:self.view.frame]; [self.view addSubview:self.scrollView]; [_scrollView release]; //让视图滚动起来属性,滚动范围 //-100是为了下面的滚动圆点 self.scrollView.contentSize=CGSizeMake(7 * WIDTH, HEIGHT - 100); //按页进行滚动 self.scrollView.pagingEnabled=YES; //滚动的图片 for (int i = 1; i < 8; i++) { NSString *imageName =[NSString stringWithFormat:@"h%d.jpeg",i]; //创建滚动的七个视图 UIImageView *imageView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]]; //设置图片的起始位置 imageView.frame=CGRectMake(i * WIDTH - WIDTH, 0, WIDTH, HEIGHT-100); [self.scrollView addSubview:imageView]; [imageView release]; } // 关闭边界回弹效果 self.scrollView.bounces=NO; //关闭滚动条 self.scrollView.showsHorizontalScrollIndicator=NO; self.scrollView.showsVerticalScrollIndicator=NO; //设置代理人 self.scrollView.delegate=self; //创建圆点 UIPageControl *page=[[UIPageControl alloc] initWithFrame:CGRectMake(100, 580, 200, 40)]; page.backgroundColor=[UIColor whiteColor]; [self.view addSubview:page]; [page release]; //圆点个数 page.numberOfPages=7; //圆点颜色 page.pageIndicatorTintColor=[UIColor cyanColor]; //选中点的颜色 page.currentPageIndicatorTintColor=[UIColor yellowColor]; page.tag=1000; //显示第几页在第一张 self.scrollView.contentOffset=CGPointMake(WIDTH * self.number, 0); NSString *str=[NSString stringWithFormat:@"第%ld张",self.number+1]; self.navigationItem.title=str; } //点随着图片滚动动 -(void)scrollViewDidScroll:(UIScrollView *)scrollView { UIPageControl *page=(UIPageControl *)[self.view viewWithTag:1000]; page.currentPage =self.scrollView.contentOffset.x / WIDTH; NSString *str=[NSString stringWithFormat:@"第%ld张",page.currentPage + 1]; self.navigationItem.title=str; } - (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 ![这里写图片描述](http://img.blog.csdn.net/20150810083852590)
相关文章推荐
- UI连载五--常用UI控件—Label、Button、UITextField、UIImageView、UISlider、UISwitch、UIActivityIndicatorView等
- iOS UI08_tableView省市区字典数组
- UIViewController
- UITextView
- STL 之 优先队列(priority_queue)
- Regionals 2009 >> Asia - Hsinchu UVALIVE, 4529 A Constrained Queen Game - 搜索剪枝
- UI设计中的结构设计
- POJ 题目2778 DNA Sequence(AC自动机,矩阵快速幂)
- Unique Paths II
- Unique Paths I
- Regionals 2009 Asia - Hsinchu UVALIVE, 4525 - Clues 搜索
- UI019---ITableviewcell的性能问题和缓存优化
- UI018---UITableView使用
- UI017---UITableView的入门
- Builder(建造者)设计模式
- UI016----图片缩放
- UI015---UIScrollView控件介绍
- 【POJ 2442】Sequence
- UVA_10911_FormingQuizTeams
- hdoj 1711 Number Sequence 【KMP】