我的应用程序中有一个信息页面。由于本地化的不同,文本长度可能会有所不同。除此之外,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];
}
请提供建议,先行致谢。