我将如何动态调整 a 的高度UIScrollView
?基本上我UILabels
创建了一堆(UILabels 的确切数量是随机的),并且UIScrollView
是自动调整其高度以适应UILables
. 这是我迄今为止在viewDidLoad
.
- (void)viewDidLoad
{
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(320
, 1500)];
scroller.indicatorStyle = UIScrollViewIndicatorStyleWhite;
{
这是创建额外 UILavels 的操作
-(IBAction)scheduale{
int i;
for(i=0; i<[self retrieveTime] ; i++){
//Add time label
UILabel *timeLabel = [[UILabel alloc] init];
timeLabel.frame = CGRectMake(10, (i+1) * 21, 31, 20);
timeLabel.textColor = [UIColor whiteColor];
timeLabel.backgroundColor = [UIColor colorWithRed:76.0/225.0 green:76.0/225.0 blue:76.0/225.0 alpha:1.0];
NSString *labelString;
labelString = [[NSNumber numberWithInt:i] stringValue];
timeLabel.text = labelString;
timeLabel.textAlignment = UITextAlignmentCenter;
//theLabel.tag = (i+1) * 100;
[scroller addSubview:timeLabel];
}