0

目前,我在我的应用程序中有这个功能,在那里我实现了一个高度很薄但宽度很长的 UIScrollview ......

每小时预报

如您所见,UIScrollView 与 backgroundview 重叠...不是白色背景是 UIView,我将 UIScrollView 作为 SUBVIEW 添加到其中。

问题是,当 UIScrollView 刚刚添加到子视图时,它是如何与黑色背景内容重叠的?

这是我的 UIScrollView 的 init 方法。

self = [super init];
if (self) {
    self.frame = CGRectMake(0, 0, 280, 70);
    self.contentSize = CGSizeMake(480, 70);
    self.showsHorizontalScrollIndicator = NO;
    self.bounces = NO;
}

下面是我如何将 UIScrollView 添加到名称为 ForecastView 的 UIView(白色背景视图)中:

_hourlyForecast = [[hourlyForecastScrollView alloc] init:_city state:_state icons:_icons times:_times temps:_temps];
_hourlyForecast.backgroundColor = [UIColor blueColor];
_hourlyForecast.frame = CGRectMake(20, 20, self.ForecastView.bounds.size.width, 70);
[_ForecastView addSubview:_hourlyForecast];
4

1 回答 1

3

默认情况下,视图不会剪切它的子视图。要启用剪辑,请设置 UIView clipsToBounds属性,或在 Interface Builder 中设置

在此处输入图像描述

(图片归功于Mugunth

于 2013-06-27T18:56:46.150 回答