Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何自动调整UIScrollView的大小_Ios_Uiview_Uiscrollview - Fatal编程技术网

Ios 如何自动调整UIScrollView的大小

Ios 如何自动调整UIScrollView的大小,ios,uiview,uiscrollview,Ios,Uiview,Uiscrollview,我的应用程序中有一个infopage。文本长度可能因本地化而有所不同。除此之外,它还有一个3.5英寸的屏幕,比一个4英寸的显示屏的不动产小。所以我试图实现的是UILabel在ScrollView中“增长”,ScrollView适应屏幕 这是我的代码: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // Crea

我的应用程序中有一个infopage。文本长度可能因本地化而有所不同。除此之外,它还有一个3.5英寸的屏幕,比一个4英寸的显示屏的不动产小。所以我试图实现的是UILabel在ScrollView中“增长”,ScrollView适应屏幕

这是我的代码:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

// Create a ScrollView and a label
UIScrollView *infoScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(20.0f, 55.0f, 300.0f, 400.0f)];

CGRect labelFrame = CGRectMake(0, 0, 280, 800);
UILabel *infoLabel = [[UILabel alloc] initWithFrame:labelFrame];

NSString *labelText = NSLocalizedString (@"InfoText",@"");
[infoLabel setText:labelText];

// Tell the label to use an unlimited number of lines
[infoLabel setNumberOfLines:0];
[infoLabel setBackgroundColor:[UIColor clearColor]];
[infoLabel setFont:[UIFont boldSystemFontOfSize:17]];
infoLabel.textColor = [UIColor colorWithRed:255 green:255 blue:255 alpha:1.0];
[infoLabel sizeToFit];
infoScroll.contentSize = CGSizeMake(infoScroll.contentSize.width, infoLabel.frame.size.height);
[infoScroll addSubview:infoLabel];

[self.view addSubview:infoScroll];

}

请提供建议,提前感谢

通过以下方式修改您的功能:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    // Create a ScrollView and a label
    UIScrollView *infoScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(20.0f, 55.0f, self.view.frame.size.width - 20.0, self.view.frame.size.height - 55)];
    infoScroll.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    UILabel *infoLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    infoLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;        

NSString *labelText = NSLocalizedString (@"InfoText",@"");
    [infoLabel setText:labelText];

    // Tell the label to use an unlimited number of lines
    [infoLabel setNumberOfLines:0];
    [infoLabel setBackgroundColor:[UIColor clearColor]];
    [infoLabel setFont:[UIFont boldSystemFontOfSize:17]];
    infoLabel.textColor = [UIColor colorWithRed:255 green:255 blue:255 alpha:1.0];
    //[infoLabel sizeToFit];

    CGSize infoLabelSize = [infoLabel.text sizeWithFont:infoLabel.font
               constrainedToSize:CGSizeMake(infoScroll.frame.size.width, 5000)
                   lineBreakMode:UILineBreakModeWordWrap];

    infoLabel.frame = CGRectMake(0, 0, infoLabelSize.width, infoLabelSize.height);
    infoScroll.contentSize = infoLabelSize;
    [infoScroll addSubview:infoLabel];

    [self.view addSubview:infoScroll];

}

你的问题是什么?如上所述,我希望滚动视图适应屏幕的大小。我不知道怎么做。你可能想看看自动调整大小的面具。谢谢你的回复和帮助。我做了一些改变,但效果不太好。在3.5英寸显示屏上,这是正常的,但在4英寸显示屏上,滚动视图变短。有什么建议吗?太好了!!!这就成功了。我只需要在我的本地化文本中添加几个blanc文本行,现在它就可以完美地工作了。非常感谢你。我希望我能获得和你一样多的知识。也许这需要经验。我希望会。非常感谢你。