UIScrollView,UIPageControl

#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UIScrollViewDelegate>
@end
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//组成
//上面 一个scrolview,一个addlable
//中间一个pagecontrol
//下面一个myScrollview一个remove按钮
self.view.backgroundColor=[UIColor greenColor];
/***************UIScrollView*********************************/
UIScrollView *scrolview=[[UIScrollView alloc]initWithFrame:CGRectMake(20, 20, 280, 180)];//高度等于图片高度,宽度小于图片宽度
scrolview.backgroundColor=[UIColor blueColor];
scrolview.contentSize=CGSizeMake(770, 180);//有效的显示范围小于图片,图片不完全显示
UIImageView *imageview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 770, 180)];
imageview.image=[UIImage imageNamed:@"zhizhu"];
imageview.backgroundColor=[UIColor yellowColor];
[scrolview addSubview:imageview];
[self.view addSubview:scrolview];
UILabel *addlable=[[UILabel alloc]initWithFrame:CGRectMake(310, 150, 160, 30)];
addlable.text=@"啊,多么美得一幅画!";
[scrolview addSubview:addlable];
scrolview.pagingEnabled=YES;//分页显示的效果
[scrolview setContentOffset:CGPointMake(250, 0) animated:YES];//加载后横向滚动300像素
scrolview.scrollEnabled=YES;//是否可以滚动的属性
scrolview.userInteractionEnabled=YES;//设置交互的属性
scrolview.showsHorizontalScrollIndicator=YES;
scrolview.showsVerticalScrollIndicator=YES;//设置滚动条是否显示
scrolview.bounces=NO;//设置边界的反弹效果,滚到边界将不再滚动
//添加下面的myScrollview
int weigth=700*280/1066;
UIScrollView *myScrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(50, 250,weigth, 280)];//显示框大小
myScrollview.tag=121;
myScrollview.backgroundColor=[UIColor redColor];
myScrollview.contentSize=CGSizeMake(weigth*5, 280);//有效显示区域
myScrollview.delegate=self;//添加代理
//添加图片组
for (int i=0; i<5; i++) {
UIImageView *imageview1=[[UIImageView alloc]initWithFrame:CGRectMake(weigth*i, 0, weigth, 280)];
NSString *imageName=[NSString stringWithFormat:@"%d.jpg",i+1];
imageview1.image=[UIImage imageNamed:imageName];
[myScrollview addSubview:imageview1];
}
//最后一页添加一个按钮
UIButton *remove=[UIButton buttonWithType:UIButtonTypeCustom];
remove.frame=CGRectMake(weigth*4+(weigth-100)/2, 220, 100, 35);//设置按钮位置,可以随页面移动
remove.backgroundColor=[UIColor orangeColor];
[remove setTitle:@"开始体验" forState:UIControlStateNormal];
[remove addTarget:self action:@selector(doRemoveScrollView:) forControlEvents:UIControlEventTouchUpInside];//添加事件
[myScrollview addSubview:remove];//添加按钮
myScrollview.pagingEnabled=YES;//按页翻动
[self.view addSubview:myScrollview];
//添加pagecontrol小白点,每个小白点一个页数
UIPageControl *pagecontrol=[[UIPageControl alloc]initWithFrame:CGRectMake(0, 210, 320, 30)];
pagecontrol.tag=122;
pagecontrol.backgroundColor=[UIColor blueColor];
[pagecontrol addTarget:self action:@selector(pageControlSelector:) forControlEvents:UIControlEventValueChanged];//添加事件
pagecontrol.numberOfPages=5;//控制显示的页数
pagecontrol.currentPage=0;//默认显示第几页;
[self.view addSubview:pagecontrol];
}
//每次scrollView变化后小白点位置变化
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
UIPageControl *pagec=(UIPageControl *)[self.view viewWithTag:122];
CGPoint point1=scrollView.contentOffset;
NSLog(@"%f",(float)point1.x);
[pagec setCurrentPage:point1.x/183];
}
//每次pagecontrol变动后scrollview都跟着变化
-(void)pageControlSelector:(UIPageControl *)sender{
UIScrollView *getscroll=(UIScrollView *)[self.view viewWithTag:121];//拿到scrollview;知道滚动对象
CGSize size=getscroll.frame.size;
CGRect reck1=CGRectMake((sender.currentPage *size.width), 0, size.width, size.height);
[getscroll scrollRectToVisible:reck1 animated:YES];
}
//按钮的方法
-(void)doRemoveScrollView:(id)sender{
UIView *removeView=[self.view viewWithTag:121];
[removeView removeFromSuperview ];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
UIScrollView,UIPageControl的更多相关文章
- UIScrollView,UIPageControl,UIImageView 实现图片轮播的效果
上一篇博客介绍了如何将XCode创立的项目提交到Git版本控制,这次就直接做一个图片轮播的展示demo,刚好可以把UIScrollView.UIPageControl.UIImageView这三个控件 ...
- 启动图实现:UIScrollView+UIPageControl简单实现
#import "MJViewController.h"#import "RootViewController.h" @interface MJViewCont ...
- iOS纯代码制作欢迎界面——UIScrollView, UIPageControl, UIImageView,UIButton, NSTimer
欢迎界面,还是比较简单的,一个UIScrollView控件,一个UIPageControl,几个UIImageView即可摆平.在这里光玩这些,就显得诚意不足了.特意拓展一下,再加几个UIButton ...
- IOS初级:UIScrollView & UIPageControl
UIScrollView其实构建的就像一列很长的火车,每滑动一个屏幕,展示一节车厢. //主屏幕高度 #define kScreenHeight [UIScreen mainScreen].bound ...
- swift开发之 -- 自动轮播图(UIScrollView+UIPageControl+Timer)
比较简单,原理就不说了,这里只做记录: 代码如下: 1,准备 var pageControl:UIPageControl? var myscrollView:UIScrollView? var myT ...
- 第二、UIScrollView的使用大全
UIScrollView UIPageControl 的使用 2011-11-19 16:48 4690人阅读 评论(0) 收藏 举报 imagescrollspringiphone // // ...
- FlipView For Xamarin.Form 之 IOS
之前写过两篇博文 是关于 Android 和 Windows Phone 下的 FlipView 的实现. 上上周,有个印度佬通过 GitHub 找到我, 问我有没有打算个 ios 端的,还说比较了相 ...
- iOS:核心动画的详解介绍:CAAnimation(抽象类)及其子类
核心动画的详解介绍:CAAnimation(抽象类) 1.核心动画基本概念 Core Animation是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍! 使用它 ...
- iOS回顾笔记(05) -- 手把手教你封装一个广告轮播图框架
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...
随机推荐
- JavaScript目录
1. 如何快速检查js语法学习Javascript 2. 如何快速掌握CSS(各种CSS工具)
- nopCommerce 数据缓存
为了提高一个系统或网站的性能和IO吞吐量,我们一般都会采用缓存技术.当然NopCommerce也不例外,本文我们就来给大家分析一下nop中Cache缓存相关类设计.核心源码及实现原理. 一.Nop.C ...
- mysql二进制包安装与配置实战记录
导读 一般中小型网站的开发都选择 MySQL 作为网站数据库,由于其社区版的性能卓越,搭配 PHP .Linux和 Apache 可组成良好的开发环境,经过多年的web技术发展,在业内被广泛使用的一种 ...
- 使用Calendar 将当月日历打印出来
package com.date; import java.text.DateFormatSymbols; import java.util.Calendar; import org.junit.Te ...
- [WinForm] VS2010的程序打包封装
因为学习的要求,我需要把自己的程序进行打包封装,开始也是苦恼,没有找到很好的办法,但并没有放弃,终于发现了一个差不多的文章,于是摸索着进行,可喜的是是成功了,下面和大家分享一下. 第一步:前提是你已经 ...
- PHP实现遍历、复制、删除目录
一.遍历 opendir 具体函数我就不解释了,直接看代码理解: <?php header("Content-Type:Text/html;charset=utf8"); $ ...
- 【Python Lib】解析HTML利器 BeautifulSoup
- - 官方API文档,中文版 http://www.crummy.com/software/BeautifulSoup/bs4/doc/index.zh.html - 以后会把常用的摘录出来
- ubuntu下安装redis
(1)进去 /usr/local目录下 cd /usr/local 若没有local这个文件夹则创建一个 sudo mkdir /usr/local sudo chmod 777 ...
- 精通CSS高级Web标准解决方案(1-2 层叠与特殊性)
层叠与特殊性 选择器的特殊性分成四个等级,a.b.c . d 如果样式是行内样式,那么a=1 b=ID选择器的总数 c=类.伪类.属性选择器的总数 d=标签选择器与伪元素选择器数量 例如:style ...
- Oracle 基础——索引
一.索引 索引是一种快速访问数据的途径,可提高数据库性能.索引使数据库程序无须对整个表进行扫描,就可以在其中找到所需的数据,就像书的目录,可以快速查找所需的信息,无须阅读整本书. 二.索引存在的问题 ...