【问题标题】:scroll view control in iosios中的滚动视图控件
【发布时间】:2015-11-26 08:18:42
【问题描述】:

我是 iOS 新手, 我面临UIScrollView 的问题。卷轴在这不起作用,您能帮帮我吗:

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];

【问题讨论】:

标签: ios objective-c iphone uiscrollview contentsize


【解决方案1】:

设置UIScrollViewcontentSize

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

【讨论】:

    【解决方案2】:

    像这样设置滚动视图的内容高度

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

    【讨论】:

      【解决方案3】:

      试试这个代码:

      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
      

      【讨论】:

        【解决方案4】:

        您需要设置UIScrollViewcontentSize。如果没有设置,它将不会显示滚动。并且您的 contentSize 应该大于您的scrollView.frame.size

        现在,您的 scrollView 有一个巨大的 frame.height。使用较小的值。并为 contentSize.height 使用较高的值。

        【讨论】:

          猜你喜欢
          • 2013-01-02
          • 1970-01-01
          • 2012-06-29
          • 2012-03-30
          • 2016-12-04
          • 2016-07-07
          • 1970-01-01
          • 2023-03-08
          • 1970-01-01
          相关资源
          最近更新 更多