0

我正在尝试将标签(headerLabel)添加到另一个子视图(introPadTutorial),但它没有显示在屏幕上。有人可以帮我在哪里犯错吗?

//Header file

@property (nonatomic, retain) UIView *introPadTutorial;

//Implementation file

@synthesize introPadTutorial;

UIView *v = [_appDelegate getCurrentView];
CGRect tutorialFrame = [self getTableViewFrame];

introPadTutorial = [[UIView alloc] initWithFrame:CGRectMake(v.frame.size.width, 80, -tutorialFrame.size.width, v.frame.size.height)];
[introPadTutorial setBackgroundColor:[UIColor uberLightGray]];
[introPadTutorial setUserInteractionEnabled:YES];

UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 180, 180)];
[headerLabel setText:@"test test test"];
[headerLabel setBackgroundColor:[UIColor greenColor]];
[headerLabel setFont:[UIFont boldSystemFontOfSize:16.0f]];
[headerLabel setTextColor:[UIColor redColor]];
[headerLabel setShadowColor:[UIColor whiteColor]];
[headerLabel setShadowOffset:CGSizeMake(0, 1)];

[self.introPadTutorial addSubview:headerLabel];
[headerLabel release];

[v addSubview:introPadTutorial];
[introPadTutorial release];
4

3 回答 3

0

你的introPadTutorial观点出现了吗?initWithFrame你在它的调用中有一个负宽度。

于 2012-08-29T18:24:11.167 回答
0

可能是你的...

introPadTutorial = [[UIView alloc] initWithFrame:CGRectMake(v.frame.size.width, 80, -tutorialFrame.size.width, v.frame.size.height)];

其实应该...

introPadTutorial = [[UIView alloc] initWithFrame:CGRectMake(0, 80, tutorialFrame.size.width, v.frame.size.height)];
于 2012-08-29T18:25:01.780 回答
0

不要使用负宽度来改变位置,使用原点来改变位置。

用这个:

introPadTutorial = [[UIView alloc] initWithFrame:CGRectMake(v.frame.size.width - tutorialFrame.size.width, 80, tutorialFrame.size.width, v.frame.size.height)];

我认为这应该有助于使子视图真正出现。

于 2012-08-29T19:03:19.060 回答