#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的更多相关文章

  1. UIScrollView,UIPageControl,UIImageView 实现图片轮播的效果

    上一篇博客介绍了如何将XCode创立的项目提交到Git版本控制,这次就直接做一个图片轮播的展示demo,刚好可以把UIScrollView.UIPageControl.UIImageView这三个控件 ...

  2. 启动图实现:UIScrollView+UIPageControl简单实现

    #import "MJViewController.h"#import "RootViewController.h" @interface MJViewCont ...

  3. iOS纯代码制作欢迎界面——UIScrollView, UIPageControl, UIImageView,UIButton, NSTimer

    欢迎界面,还是比较简单的,一个UIScrollView控件,一个UIPageControl,几个UIImageView即可摆平.在这里光玩这些,就显得诚意不足了.特意拓展一下,再加几个UIButton ...

  4. IOS初级:UIScrollView & UIPageControl

    UIScrollView其实构建的就像一列很长的火车,每滑动一个屏幕,展示一节车厢. //主屏幕高度 #define kScreenHeight [UIScreen mainScreen].bound ...

  5. swift开发之 -- 自动轮播图(UIScrollView+UIPageControl+Timer)

    比较简单,原理就不说了,这里只做记录: 代码如下: 1,准备 var pageControl:UIPageControl? var myscrollView:UIScrollView? var myT ...

  6. 第二、UIScrollView的使用大全

    UIScrollView UIPageControl 的使用 2011-11-19 16:48 4690人阅读 评论(0) 收藏 举报 imagescrollspringiphone // //    ...

  7. FlipView For Xamarin.Form 之 IOS

    之前写过两篇博文 是关于 Android 和 Windows Phone 下的 FlipView 的实现. 上上周,有个印度佬通过 GitHub 找到我, 问我有没有打算个 ios 端的,还说比较了相 ...

  8. iOS:核心动画的详解介绍:CAAnimation(抽象类)及其子类

    核心动画的详解介绍:CAAnimation(抽象类)   1.核心动画基本概念 Core Animation是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍! 使用它 ...

  9. iOS回顾笔记(05) -- 手把手教你封装一个广告轮播图框架

    html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...

随机推荐

  1. Linux内核分析笔记 与Linux内核开发理论

    http://www.cnblogs.com/hanyan225/category/308793.html

  2. spring security源码分析之web包分析

    Spring 是一个非常流行和成功的 Java 应用开发框架.Spring Security 基于 Spring 框架,提供了一套 Web 应用安全性的完整解决方案.一般来说,Web 应用的安全性包括 ...

  3. 代码片段---S3C2440按键中断驱动程序的设计

    用到的知识: 中断  等待队列  睡眠  select  poll  misc http://pan.baidu.com/s/1bneSG5h

  4. Linux根文件系统的制作

    转载:http://www.cnblogs.com/hnrainll/archive/2011/06/09/2076655.html 1. 根文件系统 文件系统是包括在一个磁盘(包括光盘.软盘.闪盘及 ...

  5. 关于Android LayoutInflater的解释

    LayoutInflater的作用就是动态加载xml布局好的界面,类似于findViewById()来获取已经定义好的控件一样.不同点是LayoutInflater是用来找res/layout/下的x ...

  6. Tika

    1.解析图片 @Test public void test1Image() throws IOException, SAXException, TikaException{ String filePa ...

  7. spring mvc 接收页面表单List

    很少写博客,如果写的不好请多多包涵! 最近在用Spring mvc时遇到一个问题,在网上搜了很多资料.几乎没看到解决办法! 例如:当我们在做批量添加或者更新时,在Controller层接收表单数据的问 ...

  8. PetaPOCO 一对多 多对一 多对多

    PetaPoco支持将结果集中的一行映射到到两个以及更多POCO,但是如何处理一对多和多对多关系? 1.PetaPoco 支持将结果映射为多个POCO类型,提供了另一种方法来处理SQL的Join查询. ...

  9. java根据图片和文字生成自定义图片

    import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; i ...

  10. iOS数据持久化存储:归档

    在平时的iOS开发中,我们经常用到的数据持久化存储方式大概主要有:NSUserDefaults(plist),文件,数据库,归档..前三种比较经常用到,第四种归档我个人感觉用的还是比较少的,恰恰因为用 ...