滚动视图页面控件图像不完全适合

时间:2016-04-21 05:11:29

标签: ios objective-c uiscrollview uipagecontrol

我上面有一个视图,我有滚动视图m添加图像滚动视图作为子视图它不完全适合宽度和高度

关注https://www.cocoacontrols.com/controls/tapagecontrol 通过添加autolayout m得到问题bcz这不是autolayout

- (void)setupScrollViewImages
{
    for (UIScrollView *scrollView in self.scrollViews) {
        [self.imagesData enumerateObjectsUsingBlock:^(NSString *imageName, NSUInteger idx, BOOL *stop) {
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetWidth(scrollView.frame) * idx, 0, CGRectGetWidth(scrollView.frame), CGRectGetHeight(scrollView.frame))];
            imageView.contentMode = UIViewContentModeScaleAspectFill;
            imageView.image = [UIImage imageNamed:imageName];
            [scrollView addSubview:imageView];
        }];
    }
}

3 个答案:

答案 0 :(得分:0)

我认为以下行可能会解决您的问题

imgV.clipsToBounds=YES;

我正在使用下面的代码,它的工作正常

for (int i=0; i<count; i++) {
    // create imageView
    AsyncImageView *imgV = [[AsyncImageView alloc] initWithFrame:CGRectMake(i*topScrollView.frame.size.width, 0, topScrollView.frame.size.width, topScrollView.frame.size.height)];
    // set scale to fill
    imgV.contentMode=UIViewContentModeScaleAspectFill;
    imgV.clipsToBounds=YES;
    [[Model sharedInstance] setImageWithUrl:[imgArray objectAtIndex:i] forAsyncImageView:imgV];
    // apply tag to access in future
    imgV.tag=i+100;
    // add to scrollView
    [topScrollView addSubview:imgV];
}

答案 1 :(得分:0)

您可以强制for($i=0;$i<count($doc);$i++) { echo $doc[$i]; echo "<br>"; } 具有相同的尺寸,然后再添加到imageview

scrollview

答案 2 :(得分:0)

尝试如下,

您的视图层次结构应该是:

ScrollView - UIView - YourImageview

不要直接在scrollview上添加imageview,添加一个视图。

第二件事是设置你的imageview的内容模式UIViewContentModeScaletoFill

希望这会有所帮助:)