在我的 viewDidLoad 中,我可以让 UILabels 和 UITextFields 显示文本,但不能显示 UITextView。我在下面的代码中做错了吗?
- (void)viewDidLoad {
[super viewDidLoad];
UIView* headerWrapper = [[UIView alloc] init];
//tap gesture is for each section so we can click on it
UITapGestureRecognizer *headerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showContent:)];
header = [[UIView alloc] initWithFrame: CGRectMake(10.0, 10.0, 738.0, 40.0)];
header.backgroundColor = [UIColor blackColor];
//get the header frame
CGRect headerFrame = header.frame;
//add the gesture
[headerWrapper addGestureRecognizer:headerTap];
//add a label
UILabel* lblSectionTitle = [[UILabel alloc] initWithFrame: CGRectMake(10.0, 3.0, headerFrame.size.width, 24.0)];
lblSectionTitle.text = @"This is a test";
lblSectionTitle.font = [UIFont fontWithName:@"Helvetica" size:20.0];
lblSectionTitle.textColor = [UIColor whiteColor];
lblSectionTitle.backgroundColor = [UIColor clearColor];
[header addSubview:lblSectionTitle];
[headerWrapper addSubview:header];
//this is the wrapper for the content
UIView* contentView = [[UIView alloc] initWithFrame:CGRectMake(10.0, headerFrame.size.height + 15.0, headerFrame.size.width, 200.0)];
contentView.backgroundColor = [UIColor redColor];
UITextView* tvContent = [[UITextView alloc] initWithFrame:CGRectMake(0.0, 0.0, headerFrame.size.width, 200.0)];
[tvContent setText:@"This is a content test."];
tvContent.textColor = [UIColor blackColor];
tvContent.backgroundColor = [UIColor clearColor];
tvContent.font = [UIFont fontWithName:@"Trebuchet" size:18.0];
[contentView addSubview:tvContent];
[headerWrapper addSubview:contentView];
[self.view addSubview:headerWrapper];
NSLog(@"%@", tvContent.text);
}