简体   繁体   English

在ios中滚动视图控件

[英]scroll view control in ios

I am new to iOS, Am facing an issue with UIScrollView . 我是iOS的新手,我遇到了UIScrollView的问题。 The scroll is not working in this, can you please help me: 卷轴不起作用,请你帮我:

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 310,300, 999)];

label.text = self.selString;
label.numberOfLines = 0;
// [self.view addSubview:label];

UIImageView *image = 
  [[UIImageView alloc] initWithFrame:CGRectMake(10, 20, 300, 300)];
image.backgroundColor = [UIColor greenColor];
image.tag = 50;
image.userInteractionEnabled=YES;
image.autoresizesSubviews = YES;
image.alpha = 0.93;
image.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://opensum.in/app_test_f1/45djx96.jpg"]]];   // working code
//[self.view addSubview:image];

self.title = @"Full Blog";

CGRect scrollViewFrame = CGRectMake(0,0, 320, 999);
scrollView = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
scrollView.pagingEnabled =YES;
[self.view  addSubview:scrollView];

scrollView.tag=1000;


[scrollView addSubview:label];
[scrollView addSubview:image];

Set UIScrollView contentSize : 设置UIScrollView contentSize

CGSize contentSize = CGSizeMake([[UIScreen mainScreen]bounds].size.width, 1000);
[scrollView setContentSize:contentSize];

You need to set the contentSize of your UIScrollView . 您需要设置UIScrollViewcontentSize Without setting that, it' won't show scrolling. 没有设置,它将不会显示滚动。 And your contentSize should be bigger than your scrollView.frame.size . 并且您的contentSize应该大于您的scrollView.frame.size

Right now, your scrollView has a huge frame.height. 现在,你的scrollView有一个巨大的frame.height。 Use a smaller value. 使用较小的值。 And use the higher value for contentSize.height. 并为contentSize.height使用更高的值。

Try this code : 试试这段代码:

UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(10, 310,300, 999)];

label.text=self.selString;
label.numberOfLines=0;

UIImageView *image=[[UIImageView alloc]initWithFrame:CGRectMake(10, 20, 300, 300)];
image.backgroundColor = [UIColor greenColor];
image.tag = 50;
image.alpha = 0.93;
image.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://opensum.in/app_test_f1/45djx96.jpg"]]];

CGRect scrollViewFrame = CGRectMake(0,0, 320, 999);
scrollView = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
scrollView.tag=1000;

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

scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 999);// your scroll scroll height give here

像这样设置scrollview的内容高度

[scrollView setContentSize:(CGSizeMake(320, 999))];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM