如何在滚动视图中将UIImage放在UILabel或UITextView下面

时间:2014-06-24 05:04:40

标签: ios uiscrollview uiimageview uilabel

如何在UILabel中的UITextView下设置UIImageViewUIScrollView,以便在滚动图片时,标签或文字也应同时滚动它同时。需要有关此的指导。

1 个答案:

答案 0 :(得分:0)

您必须实施UIScrollView,然后在您的案例中添加所需的子视图(UIImageViewUILabel)。

在你viewDidLoad

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scrollView.backgroundColor = [UIColor redColor];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, scrollView.frame.size.width * 2, 100)];
imageView.backgroundColor = [UIColor blueColor];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(imageView.frame.size.width, 0, imageView.frame.size.width * 2, 40)];
label.text = @"Hello World";

[self.view addSubview:scrollView];
[scrollView addSubview:imageView];
[scrollView addSubview:label];

不要忘记设置UIScrollView的内容大小>你的框架:

scrollView setContentSize:CGSizeMake(self.view.frame.size.width * 2, self.view.frame.size.height);

这应该为您提供所需的指导。