我需要将标签和其他对象放置在可滚动视图中。但这不会添加2个标签,每次运行程序时我只会得到白色背景
- (void) initLayout:(CGRect)frame
{
self.backgroundColor = [UIColor whiteColor];
UIFont *customFont = [UIFont fontWithName:@"HelveticaNeue" size:40.0]; //custom font
scrollView = [[UIScrollView alloc] initWithFrame:frame];
[self addSubview:scrollView];
oponent = [[UILabel alloc] init];
oponent.font = customFont;
oponent.textColor = [UIColor blackColor];
oponent.textAlignment = NSTextAlignmentCenter;
oponent.text = @"TEST";
[scrollView addSubview:oponent];
proponent = [[UILabel alloc] init];
proponent.font = customFont;
proponent.textColor = [UIColor blackColor];
proponent.textAlignment = NSTextAlignmentCenter;
proponent.text = @"TRY";
[scrollView addSubview:proponent];
}
最佳答案
您没有为支持者和反对者标签设置框架。设置其框架,并设置滚动视图的内容大小。您还可以通过在标签上设置一些边框颜色来进行检查。
要检查您的scrollview是否正常工作,请在头文件中添加UIScrollViewDelegate,然后使用委托方法。
scrollView.delegate = self;
scrollView.scrollEnabled = YES;
添加以下委托方法,并使用断点检查是否被调用
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
}