UIScrollView和PageControl:视图之间的空间 [英] UIScrollView and PageControl: space between views

查看:31
本文介绍了UIScrollView和PageControl:视图之间的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在由UIScrollView和PageControl显示的视图之间添加一些黑色空间.每个视图都是一个简单的视图控制器,其中包含一个UiImageView,类似于相册.我想添加空间,所以当用户切换页面"/照片时,两者之间会有一定的差距.

Is it possible to add some black space between views that are shown by a UIScrollView and PageControl. Each of these views is a simple view controller with an UiImageView in it, similar to the photo album. I want to add the space, so when the users are switching "pages"/photos, there is some gap in between.

    scrollArea.pagingEnabled = YES;
    scrollArea.contentSize = CGSizeMake(scrollArea.frame.size.width * [photos count], scrollArea.frame.size.height);
    scrollArea.showsHorizontalScrollIndicator = NO;
    scrollArea.showsVerticalScrollIndicator = NO;
    scrollArea.scrollsToTop = NO;
    scrollArea.delegate = self;

我不想缩小图像,但是可以解决问题.有什么想法吗?

I wouldn't want to make the images smaller, but that would do the trick. Any ideas?

推荐答案

是的,您可以完全控制UIScrollView内所有UIView的位置以及页面控件相对于scrollview的位置.没有完成自动布局,您需要正确设置所有对象的frame属性,以使它们恰好"适合滚动视图的页面"(可见区域=一个页面")

Yes, you have full control over placement of all UIViews inside of the UIScrollView and the placement of the page control in relation to the scrollview. There is no automatic layout done, it's up to you to properly set the frame property of all the objects so that they fit "nicely" within the "page" of the scrollview (visible area = one "page")

以下是在每个页面中特定x,y的滚动视图中向多个页面"添加内容的示例:

Here's an example off adding content to multiple "pages" in a scrollview at a particular x,y within each page:

NSMutableArray *myLabels = [NSMutableArray arrayWithCapacity:numPages];
CGFloat itemX = 10;
CGFloat itemY = 20;
CGFloat itemWidth = 40;
CGFloat itemHeight = 50;

for ( int i = 0; i < numPages; ++i )
{
    UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake( itemX, itemY, itemWidth, itemHeight )];
    [myScrollView addSubview:lbl];
    [myLabels addObject:lbl];
    [lbl release];
    itemX += myScrollView.frame.size.width;
}

这篇关于UIScrollView和PageControl:视图之间的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆