我对UIscroll视图有一些问题。我已经查看了它的参考条目,但我似乎无法找到如何解决它们。基本上我正在尝试将UIlabel插入到尺寸为320 x 270的Scroll视图中(目前这个尺寸是任意的)。我的问题是我似乎无法让UILabel出现在视图的左上角。
detailView.frame = frameDFull; // frameDFull = 320 x 500
myView.frame = CGRectMake(0, 150, 320, 270); //myFrame is the scroll view
myView.contentMode = UIViewContentModeScaleAspectFit;
myView.contentSize = CGSizeMake(320, 270);
[self.view addSubview:myView];
//UIView *viewHolder = [[UIView alloc]init];
UILabel *eventDesc = [[UILabel alloc] init];
eventDesc.bounds = CGRectMake(0, 0, 320, 100);
//eventDesc.backgroundColor = [UIColor clearColor];
eventDesc.text = @"Appears off the screen partially";
[myView addSubview: eventDesc];
[eventDesc release];
我可以说我可能忘了在这里做点什么。但我不确定是什么。我尝试使用内容对齐,看看它本质上是一个UIview,但没有发生任何事情。
答案 0 :(得分:0)
尝试替换
UILabel *eventDesc = [[UILabel alloc] init];
与
UILabel *eventDesc = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
并删除设置边界的行。你应该对任何UIView(及其子类)使用initWithFrame初始化器,因为frame determines the view's location within its superview, while the bounds determines the view's location within itself.