我的問題:我有一個白色的窗口,我不明白爲什麼。 我嘗試了一些解決方案,但沒有任何工作。 Thx爲您提供幫助。在scrollView中添加標籤
CGFloat largeurDevice = [UIScreen mainScreen].bounds.size.width;
CGFloat longueurDevice = [UIScreen mainScreen].bounds.size.height;
CGRect rectScrollView = CGRectMake(0,longueurDevice/2,largeurDevice,longueurDevice/2);
UIScrollView *monScrollView = [[UIScrollView alloc] initWithFrame:rectScrollView];
[self.view addSubview: monScrollView];
for (int i = 0; i < 10; i++)
{
CGRect rectImage = CGRectMake(0,longueurDevice/2+i*30,320,30); // Définition d'un rectangle
CGRect rectLabel = CGRectMake(10,longueurDevice/2+i*30,320,30);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:rectImage];
imageView.image = [UIImage imageNamed:@"barreTest.png"];
[monScrollView addSubview: imageView];
UILabel *monLabel = [[UILabel alloc] initWithFrame: rectLabel];
monLabel.text = @"Ceci est un label";
[monScrollView addSubview: monLabel];
}
您將在滾動視圖的可見高度下添加圖像視圖和標籤。這可能是也可能不是你想要的。如果這樣做,還需要將滾動視圖的contentSize設置爲足夠大以便添加視圖。 – rmaddy 2015-01-15 18:24:20