UIScrollView and PageControl: space between views

旧城冷巷雨未停 提交于 2019-12-08 06:49:54

问题


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?


回答1:


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")

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;
}


来源:https://stackoverflow.com/questions/5151424/uiscrollview-and-pagecontrol-space-between-views

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!