ios ios中uiscrollvieww的 indicator怎么改颜色

您当前的位置: &
& IOS UIScrollView详解 & 图片缩放功能
点击图片查看大图
IOS UIScrollView详解 & 图片缩放功能&
最小起订量:
供货总量:
发货期限:
自买家付款之日起
3 天内发货
发布时间:
17:21:05&&有效期至:长期有效
IOS&UIScrollView详解&&&图片缩放功能
一&UIScrollView&简介
UIScrollView是能滚动的视图控件,可以通过滚动的方式来展示类
二&UIScrollView常见属性
//设置UIScrollView滚动的位置
@property(nonatomic)&CGPoint&contentO&
//设置UIScrollView内容的尺寸,滚动范围
@property(nonatomic)&CGSize&contentS&
//设置UIScrollView的4周增加额外的滚动区域
@property(nonatomic)&UIEdgeInsets&contentI&
//设置UIScrollView是否需要弹簧效果
@property(nonatomic)&BOOL&
//设置UIScrollView是否能滚动
@property(nonatomic,getter=isScrollEnabled)&BOOL&scrollE&
//设置UIScrollView是否显示水平滚动条
@property(nonatomic)&BOOL&showsHorizontalScrollI
//设置UIScrollView是否显示垂直滚动条
@property(nonatomic)&BOOL&showsVerticalScrollI
三&UIScrollView&代理(delegate)
UIScrollView在滚动过程中&或者&停止滚动&时,如果需要做一些特定的操作,可用通过设置代理的方式(delegate)来监听UIScrollView的整个滚动过程,当UIScrollView发生一系列的滚动操作时,&会自动通知它的代理(delegate)对象,然后通过代理来监听UIScrollView的滚动过程。
UIScrollView将delegate需要实现的方法都定义在UIScrollViewDelegate协议中,因此UIScrollView的delegate必须遵守UIScrollViewDelegate协议,然后实现协议中相应的方法,就可以监听UIScrollView的滚动过程
//&用户开始拖拽时调用
-&(void)scrollViewWillBeginDragging:(UIScrollView&*)scrollV
//&滚动到某个位置时调用
-&(void)scrollViewDidScroll:(UIScrollView&*)scrollV
//&用户结束拖拽时调用
-&(void)scrollViewDidEndDragging:(UIScrollView&*)scrollView&willDecelerate:(BOOL)
四&内容缩放
UIScrollView不仅能滚动显示大量内容,还能对其内容进行缩放处理
当在UIScrollView身上使用捏合手势时,UIScrollView会调用代理(delegate)的viewForZoomingInScrollView方法,这个方法返回的控件就是需要进行缩放的控件,缩放涉及的属性和方法
//缩小的对小比例
@property(nonatomic)&CGFloat&minimumZoomS
//放大的最大比例
@property(nonatomic)&CGFloat&maximumZoomS&&&&
//缩放时调用
-&(UIView&*)viewForZoomingInScrollView:(UIScrollView&*)scrollV
//开始缩放的时候调用&
-&(void)scrollViewWillBeginZooming:(UIScrollView&*)scrollView&withView:(UIView&*)view
//正在缩放的时候调用
-&(void)scrollViewDidZoom:(UIScrollView&*)scrollView
五&UIScrollView无法滚动的解决办法
如果UIScrollView无法滚动,可能是以下原因:
5.1&没有设置contentSize属性
5.2&设置属性scrollEnabled&=&NO
5.3&没有接收到触摸事件(userInteractionEnabled&=&NO)
5.4&取消autolayout功能,要想scrollView滚动,必须取消autolayout
#import&&ViewController.h&
@interface&ViewController&()&UIScrollViewDelegate&
@property(nonatomic,strong)UIScrollView&*scrollV
@property(nonatomic,strong)UIImageView&*imageV
@implementation&ViewController
-&(void)viewDidLoad&{
&&&&//2.设置&UIImageView
&&&&UIImage&*image&=&[UIImage&imageNamed:@&scroll.jpg&];
&&&&self.imageView.image&=&
&&&&//2.1&设置图片范围
&&&&CGFloat&imageH&=&image.size.
&&&&CGFloat&imageW&=&image.size.
&&&&CGFloat&imageX&=&0;
&&&&CGFloat&imageY&=&0;
&&&&self.imageView.frame&=&CGRectMake(imageX,&imageY,&imageW,&imageH);
&&&&//3&设置UIScrollView&属性
&&&&//3.2&设置UIScrollView内容的尺寸,滚动范围
&&&&self.scrollView.contentSize=CGSizeMake(imageW,&imageH);
&&&&//3.2&设置UIScrollView的4周增加额外的滚动区域
&&&&CGFloat&distance&=&100.0f;
&&&&self.scrollView.contentInset&=&UIEdgeInsetsMake(distance,&distance,&distance,&distance);
&&&&//3.3&设置弹簧效果
&&&&self.scrollView.bounces&=&YES;
&&&&//3.4&设置滚动不显示
&&&&self.scrollView.showsHorizontalScrollIndicator=NO;
&&&&self.scrollView.showsVerticalScrollIndicator=NO;
&&&&//4&UIImageView&添加到&UIScrollView&中
&&&&[self.scrollView&addSubview:self.imageView];
&&&&//5&UIScrollView
&&&&[self.view&addSubview:self.scrollView];
&&&&//6&设置代理
&&&&self.scrollView.delegate&=&
&&&&//7&缩放
&&&&self.scrollView.minimumZoomScale=0.2f;
&&&&self.scrollView.maximumZoomScale=2.0f;
#pragma&mark&代理方法
//&用户开始拖拽时调用
-&(void)scrollViewWillBeginDragging:(UIScrollView&*)scrollView
&&&&NSLog(@&开始拖拽&);
//&滚动到某个位置时调用
-&(void)scrollViewDidScroll:(UIScrollView&*)scrollView
&&&&NSLog(@&拖拽中&);
//&用户结束拖拽时调用
-&(void)scrollViewDidEndDragging:(UIScrollView&*)scrollView&willDecelerate:(BOOL)decelerate
&&&&NSLog(@&结束拖拽&);
#pragma&mark&缩放
-&(UIView&*)viewForZoomingInScrollView:(UIScrollView&*)scrollView
&&&&NSLog(@&开始缩放&);
&&&&return&self.imageV
-&(void)scrollViewDidZoom:(UIScrollView&*)scrollView
&&&&NSLog(@&正在缩放&);
-&(void)scrollViewDidEndZooming:(UIScrollView&*)scrollView&withView:(UIView&*)view&atScale:(CGFloat)scale
&&&&NSLog(@&缩放结束&);
#pragma&mark&属性get方法
-&(UIScrollView&*)scrollView
&&&&if&(!_scrollView)&{
&&&&&&&&_scrollView&=&[[UIScrollView&alloc]&initWithframe:self.view.frame];
&&&&return&_scrollV
-&(UIImageView&*)imageView
&&&&if&(!_imageView)&{
&&&&&&&&_imageView&=&[[UIImageView&alloc]&init];
&&&&return&_imageV
缩放前&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&缩放后
学习链接:
学习交流群:
&本产品网址:/b2b/jiexiaotan/sell/itemid-.html在 IOS 中,对 UIScrollView 的滚动条(ScrollBar Indicators)的自定义设置接口,一直都是很少的。除了能自定义简单的样式(UIScrollViewIndicatorStyle)和是否启用外,对于 一直显示滚动条、自定义滚动条(ScrollBar Indicators)的Width 、颜色等,都是不能很方便的设置的。 虽然不能很方便,但是还是能实现的。通过一天的努力,不断的 google 和 overflow,终于找到了几个比较完美的解决办法。 本文禁止任何网站转载,严厉谴责那些蛀虫们。
本文首发于,博客园,请搜索:博客园 - 寻自己,查看原版文章
本文首发地址:UIScrollView自定义 - 一直显示滚动条(ScrollBar Indicators)、Width(宽度)、Color(颜色) - /xunziji/p/3248850.html&&下面先来一步步的分析:&1. 那些控件可以设置滚动条(ScrollBar Indicators)因为UIScrollView 是 UITableView 和 UITextView 的父类,所以可以设置的Controll:UIScrollView, UITableView, UITextView.&2. UIScrollView 的 - (void)flashScrollIndicators 方法该方法是调用 object-c 方法显示 UIScrollView 的滚动条(ScrollBar Indicators)。但是悲剧的是滚动条(ScrollBar Indicators) 只会显示大概1.5秒左右的时间,就会自动隐藏。不过该方法还是有一定的应用场景,比如你认为只要在 UIScrollView Load 的时间,右侧显示2秒的滚动条就能起到提示作用,那这个方法刚好满足你: [tableProdList reloadData];
if (tableProdList.contentSize.height & tableProdList.frame.size.height){
tableProdList flashScrollIndicators];
}&3. 滚动条(ScrollBar Indicators)是什么东西、是如何显示和隐藏掉的UIScrollView 的 滚动条(ScrollBar Indicators),就是默认右侧的 darkgray 条,当你滚动一个 UIScrollView 的时间,这个滚动条就会显示,并且显示和隐藏都是淡入和淡出的。这是,你或许就能猜到是什么了:UIImageView. 滚动条就是一个UIImageView,那个滚动条就是一个图片而已。而滚动条的消失、隐藏淡入淡出,都是设置的 UIImageView的 -(void) setAlpha 方法。& 本文禁止任何网站转载,严厉谴责那些蛀虫们。
本文首发于,博客园,请搜索:博客园 - 寻自己,查看原版文章
本文首发地址:UIScrollView自定义 - 一直显示滚动条(ScrollBar Indicators)、Width(宽度)、Color(颜色) - /xunziji/p/3248850.html4. 让滚动条一直显示 的第一种方法(如果你要快速解决问题,请直接看最后一种更完美、更快速的解决办法)在 StackOverFlow 上找解决办法的时候,很多问题的答案都指向这段代码: &#define noDisableVerticalScrollTag 836913#define noDisableHorizontalScrollTag 836914@implementation UIImageView (ForScrollView)- (void) setAlpha:(float)alpha {if (self.superview.tag == noDisableVerticalScrollTag) {
if (alpha == 0 && self.autoresizingMask == UIViewAutoresizingFlexibleLeftMargin) {
if (self.frame.size.width & 10 && self.frame.size.height & self.frame.size.width) {
UIScrollView *sc = (UIScrollView*)self.
if (sc.frame.size.height & sc.contentSize.height) {
}}if (self.superview.tag == noDisableHorizontalScrollTag) {
if (alpha == 0 && self.autoresizingMask == UIViewAutoresizingFlexibleTopMargin) {
if (self.frame.size.height & 10 && self.frame.size.height & self.frame.size.width) {
UIScrollView *sc = (UIScrollView*)self.
if (sc.frame.size.width & sc.contentSize.width) {
}}[super setAlpha:alpha];}@end&刚看到这段代码的时间,我想:这什么叼毛代码,我要设置 UIScrollView , 你却设置 UIImageV 我要设置 ScrollBar Indicators,你却设置 alpha。况且这段代码要怎么用,我靠,原文就贴出来了这段代码,连解释都没有。结果害我走了好多弯路,岂不知,这段代码就能很完美的解决。&首先要解释下这段代码,不然被其他苦逼的、熬夜的、加班的程序猿看到了,也不会用,我岂不是要被骂了?:&a. 这是一个 Category Objective-C提供了一个非常灵活的类(Class)扩展机制-类别(Category)。类别用于对一个已经存在的类添加方法(Methods)。你只需要知道这个类的公开接口,不需要知道类的源代码。需要注意的是,类别不能为已存在的类添加实例变量(Instance Variables)。 所以这段代码是继承了 UIImageView 类,并重写了 setAlpha 方法。关于如何把这段代码添加到项目中,见下图:&b. 该方法使用 Tag 来确定是否需要一直显示滚动条 因为该方法重写了 setAlpha,所以所有的 UIImageView 在加载的时间都会请求这段代码的,这世间不可能每个都处理,所以,通过 Controller 的Tag 来区分,也是不错的选择。当然,这里是比较 Tag 是否相等,你也可以比较 Tag 是否大于某个值等等。c. 通过一些列的 if 比较,确定该 UIScrollView :是水平还是垂直的滚动条、该 UIImageView 是否是想要隐藏 和 UIScrollView 的正文内容区域是否溢出来确定是否要隐藏,即是否要设置:[super setAlpha:0];d. 如果执行 [super setAlpha:0],则隐藏,return 就继续显示&使用方法:a. 按照图片中,建立 Category ,并把代码 Copy 进去&b. 在 viewDidLoad 内://一直显示滚动条prodDetailsTable.tag = 836913;&c. 要在 UIScrollView 数据绑定后,即加载完成后:flashScrollIndicators//重新绑定数据 [prodDetailsTable reloadData];[prodDetailsTable flashScrollIndicators];& 本文禁止任何网站转载,严厉谴责那些蛀虫们。
本文首发于,博客园,请搜索:博客园 - 寻自己,查看原版文章
本文首发地址:UIScrollView自定义 - 一直显示滚动条(ScrollBar Indicators)、Width(宽度)、Color(颜色) - /xunziji/p/3248850.html5. 让滚动条一直显示的第二种解决办法,包括自定义 滚动条(ScrollBar Indicators) 的Width、Color等我的页面是上面一个 UITableView, 下面一个 UITextView,结果两个元素一起显示滚动条,就丑的不行,主要是滚动条太Width,太 Black ,使整个页面的视觉就不舒服起来。没办法,看来不但要一直显示,还要"美"。之后在 /stefanceriu/UIScrollView-ScrollerAdditions 上找到了一个组件,很不错,可以实现一直显示 滚动条(ScrollBar Indicators)和自定义颜色,就是不能自定义 width,只能自己来加了: - (void)setVerticalScrollerWidth:(int)width{
CGRect frame = [self.verticalScroller frame];
frame = CGRectMake(frame.origin.x + (frame.size.width - width), frame.origin.y, width, frame.size.height);
[self.verticalScroller setFrame:frame];}- (void)setHorizontalScrollerHeight:(int)height{
CGRect frame = [self.horizontalScroller frame];
frame = CGRectMake(frame.origin.x, frame.origin.y + (frame.size.height - height), frame.size.width, height);
[self.horizontalScroller setFrame:frame];}OK,之后运行的很完美(文章下面有源码下载,下载完成后加入项目并 #import 后即可使用)。使用方法:a. 添加把下载后的文件添加进项目b. 在要使用的地方里 #import "UIScrollView+ScrollerAdditions.h"c. 要在 UIScrollView 数据绑定后,即加载完成后:flashScrollIndicators//重新绑定数据 [prodDetailsTable reloadData];//判断右侧是否一直显示滚动条if (prodDetailsTable.contentSize.height & prodDetailsTable.frame.size.height){[prodDetailsTable setAlwaysShowScrollIndicators:true];[prodDetailsTable setVerticalScrollerWidth:2];[prodDetailsTable setVerticalScrollerTintColor:[UIColor grayColor]];}& 本文禁止任何网站转载,严厉谴责那些蛀虫们。
本文首发于,博客园,请搜索:博客园 - 寻自己,查看原版文章
本文首发地址:UIScrollView自定义 - 一直显示滚动条(ScrollBar Indicators)、Width(宽度)、Color(颜色) - /xunziji/p/3248850.html&程序写累了,就来玩玩酷跑小游戏吧,嘿嘿。
雨松MOMO送你一首歌曲,嘿嘿。
IOS研究院之滚动视图UIScrollView的简单应用(九)
IOS研究院之滚动视图UIScrollView的简单应用(九)
围观16169次
编辑日期: 字体:
最近MOMO需要搞一个IOS软件的项目,搞了几天感觉还不错,进度挺快的,哇咔咔。Unity3D游戏开发暂时先告一段落,这段时间写一些IOS软件相关的东东,也算是给工作的一个总结。好啦现学现卖啦!!HOHO~~
UIScrollView在软件开发中是很常见的控件,总体来说ScrollView又可以分为两种:第一种是根据手指滑动的力度计算滚动的距离。第二种时以页面为单位一次滑动切换一页,这和IOS桌面左右滑动类似。 有了IOS提供的UIScrollView控件实现这些都不是什么难事。如下图所示,MOMO一共给页面中加载了5个View,通过手指左右滑动喔。
不知道说什么,直接上代码吧。
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
////&&ScrollViewController.m//&&ScrollView////&&Created by 雨松MOMO on 12-8-23.//&&Copyright (c) 2012年 雨松MOMO. All rights reserved.//&#import "ScrollViewController.h"&@interface ScrollViewController ()&@end&@implementation ScrollViewController&- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{&&&&self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];&&&&if (self) {&&&&&}&&&&return self;}&- (void)viewDidLoad{&&&&[super viewDidLoad];&&&&&//设置ScrollView的整体触摸与显示区域&&&&//注意 宽 高不要超过 320X480&&&&//否则会出现无法滚动的情况&&&&_scrollView = [[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320,440)] autorelease];&&&&&//设置ScrollView滚动内容的区域&&&&//它通常是需要大于ScrollerView的显示区域的&&&&//这样才有必要在ScrollerView中滚动它&&&&[_scrollView setContentSize:CGSizeMake(320 * 5, 240)];&&&&&//开启滚动分页功能,如果不需要这个功能关闭即可&&&&[_scrollView setPagingEnabled:YES];&&&&&//隐藏横向与纵向的滚动条&&&&[_scrollView setShowsVerticalScrollIndicator:NO];&&&&[_scrollView setShowsHorizontalScrollIndicator:NO];&&&&&//在本类中代理scrollView的整体事件&&&&[_scrollView setDelegate:self];&&&&&//如果你打开横向或纵向的滚动条,这里可以设置滚动条的风格&&&&// UIScrollViewIndicatorStyleDefault, 默认风格&&&&// UIScrollViewIndicatorStyleBlack,&& 黑色风格&&&&// UIScrollViewIndicatorStyleWhite&&&&白色风格&&&&//[_scrollView setIndicatorStyle:UIScrollViewIndicatorStyleBlack]&&&&&for (int i =0; i&5; i++)&&&&{&&&&&&&&&//在这里给每一个ScrollView添加一个图片 和一个按钮&&&&&&&&UIImageView *imageView= [[[UIImageView alloc] initWithFrame:CGRectMake(i * 320,0,320,440)] autorelease];&&&&&&&&[imageView setImage:[UIImage imageNamed:@"image.png"]];&&&&&&&&&UIButton * button = [UIButton buttonWithType:UIButtonTypeRoundedRect];&&&&&&&&button.frame = CGRectMake(i * 320, 10, 100, 30);&&&&&&&&&[button setTitle:@"这是一个按钮" forState:UIControlStateNormal];&&&&&&&&&[button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];&&&&&&&&&//把每页需要显示的VIEW添加进ScrollerView中&&&&&&&&[_scrollView addSubview:imageView];&&&&&&&&[_scrollView addSubview:button];&&&&}&&&&&//整体再将ScrollerView显示在窗口中&&&&[self.view addSubview:_scrollView];&&&&&//页面控制小工具&&&&//它会在底部绘制小圆点标志当前显示页面&&&&_pageControl = [[[UIPageControl alloc] initWithFrame:CGRectMake(0, 440,self.view.frame.size.width, 20)]autorelease];&&&&//设置页面的数量&&&&[_pageControl setNumberOfPages:5];&&&&//监听页面是否发生改变&&&&[_pageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventValueChanged];&&&&[self.view addSubview:_pageControl];&}&- (void)changePage:(id)sender{&&&&//得到当前页面的ID&& //int page = [sender currentPage];&&&&&//在这里写你需要执行的代码&&&&//......}&//手指离开屏幕后ScrollView还会继续滚动一段时间只到停止- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{&&& NSLog(@"结束滚动后缓冲滚动彻底结束时调用");}&-(void) scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{&&&NSLog(@"结束滚动后开始缓冲滚动时调用");}&-(void)scrollViewDidScroll:(UIScrollView*)scrollView&{&&&& //页面滚动时调用,设置当前页面的ID&&&& [_pageControl setCurrentPage:fabs(scrollView.contentOffset.x/self.view.frame.size.width)];&&&&NSLog(@"视图滚动中X轴坐标%f",scrollView.contentOffset.x);&&&&NSLog(@"视图滚动中X轴坐标%f",scrollView.contentOffset.y);}&-(void)scrollViewWillBeginDragging:(UIScrollView*)scrollView{&&&&NSLog(@"滚动视图开始滚动,它只调用一次");}&-(void)scrollViewDidEndDragging:(UIScrollView*)scrollView willDecelerate:(BOOL)decelerate{&& NSLog(@"滚动视图结束滚动,它只调用一次");&}&-(void)buttonClick{&&&&NSLog(@"按钮点击了");&}&- (void)viewDidUnload{&&&&[super viewDidUnload];}&- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{&&&&return (interfaceOrientation == UIInterfaceOrientationPortrait);}&@end
后天就要坐上火车去成都了,然后去九寨沟旅游啦。希望这是一趟美好的旅途,一周后北京再见!!
源码下载地址:
本文固定链接:
转载请注明:
MOMO与MO嫂提醒您:亲,如果您觉得本文不错,快快将这篇文章分享出去吧 。另外请点击网站顶部彩色广告或者捐赠支持本站发展,谢谢!
作者:雨松MOMO
专注移动互联网,Unity3D游戏开发
如果您愿意花10块钱请我喝一杯咖啡的话,请用手机扫描二维码即可通过支付宝直接向我捐款哦。
您可能还会对这些文章感兴趣!Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:
I have a UIScrollView which I create and size dynamically using...
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width , length);
I then add subviews to the UIScrollView.
I do have scrollView.showsVerticalScrollIndicator = YES;
When scrolling the scroll indicator never appears.
Even if I call [scrollView flashScrollIndicators] nothing happens.
4,15121923
Had the same problem and couldn't find the cause. The last answer gave the final hint: whenever I added new subviews I first removed all existing subviews from the scrollview (and apparently also the scroll indicators).
After checking in my loop, if the subview really was of the kind I wanted to be removed the scroll indicators showed up:
for (NSObject * subview in [[[scrollView subviews] copy] autorelease]) {
if ([subview isKindOfClass:[MySubView class]]) {
[(MySubView*)subview removeFromSuperview];
Update: changed code to Nikolai's suggestion
When I've dealt with this before, in my implementation of a grid, I would occasionally get some cells over the top of the scroll indicator. To fix this I am now inserting subviews at index 0 rather than adding them, which adds them to the top. So try something like this:
[scrollview insertSubview:subview atIndex:0];
For me, the horizontal indicator had mysteriously disappeared in my app on iOS 7. Later found out that for some strange reason, I had to enable both Shows Horizontal Indicator and Shows Vertical Indicator to make the horizontal one show up. If I set it to not show the vertical indicator, it would also not show horizontal indicator.
1,29311126
I fix this by adding this code after add new subview:
self.showsVerticalScrollIndicator = NO;
self.showsVerticalScrollIndicator = YES;
5,72672848
It can happen also if the parent of the scrollview is smaller horizontally than the scroll view itself :
The scroll bar is stuck to the right side of the ScrollView / TableView and this right side is not visible due to the parent bounds ( with a clipToBounds hidding it for instance).
I've seen this issue so I share it in case it can help.
Just check the width of your ScrollView's frame not to be bigger than the width of its parent view frame.
2,97121335
It will also happen (at least in the case of a UITableView) if the contentSize is too small for the table view to scroll. If you have enabled bouncing, then the tableview does not actually scroll and does not display the indicators therefore. Try fitting more content inside.
Noticed this when the UIScrollView was a 48 px tall horizontal band, scrollable horizontally. Maybe Cocoa decides the area is too small for a scroll indicator...
36.2k1377172
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Upcoming Events
Top questions and answers
Important announcements
Unanswered questions
By subscribing, you agree to the
Stack Overflow works best with JavaScript enabled(1)创建一个单视图工程,添加图片到工程
@interface ViewController : UIViewController {
UIScrollView *scrollV//申明一个滚动视图
(3)创建一个滚动视图,设置它的属性和内容,把imageview添加到scrollview,把scrollview添加到self.view
- (void)viewDidLoad
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(150,250, 400, 500)];
scrollView.backgroundColor = [UIColor yellowColor];
scrollView.contentSize =CGSizeMake(562, 789); // 设置内容大小,可以滚动的大小,默认是0(没有滚动效果),这里我放置的是宽562,高789的图片,所以就设置的这个了。
scrollView.showsHorizontalScrollIndicator = NO;//滚动的时候是否有水平的滚动条,默认是有的
scrollView.showsVerticalScrollIndicator = YES;//滚动的时候是否有垂直的滚动条,默认是有的
scrollView.bounces = NO;//默认的是yes(滚动到边界会有反弹回来的效果),设置为no(滚动到边界会停止)
scrollView.pagingEnabled = YES;//默认是no,设置为yes的时候,当你滑动的时候会自动滚动到边界
scrollView.scrollEnabled = NO;//是否可以滚动
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 562, 789)];
imageView.image = [UIImage imageNamed:@&Bentley.png&];
[scrollView addSubview:imageView];
[self.view addSubview:scrollView];
&此文从网络中自动搜索生成,不代表本网站赞成被搜索网站的内容或立场
&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&
&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&& 2:38:45
软件世界网- &2014 蜀ICP备号 三峰网旗下网站}

我要回帖

更多关于 ios uiscrollview用法 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信