这个问题看起来很平常..但我昨天遇到了一个问题,我在xib中添加了一个标签,并为它创建了outlet,我想在标签内有多条线,多个按钮,所以我决定在里面添加新的子标签……
UILabel *label;
label = [[UILabel alloc] initWithFrame:initial_rect];
label.font = [UIFont systemFontOfSize:[UIFont smallSystemFontSize]];
label.text = sel_obj->start_time;
label.backgroundColor = [UIColor whiteColor];
[xib_label addSubview:label]当我尝试这样做时,它不工作,然后我在self.view中添加了相同的标签,它工作得很好。那么,当我想要在使用xib添加的标签中添加标签时,我需要做什么呢?我是不是错过了什么..谢谢..。
发布于 2013-01-09 15:22:28
我很久以前就遇到过这种情况。
仅供参考:
我认为问题出在initial_rect,它在视图的框架中,但不在xib_label的框架之外。标签的框架是相对于xib_label的,而不是self.view的。
您可以尝试这样做:
UILabel *label;
CGRect rect = (CGRect){0, 0, 10, 10};
label = [[UILabel alloc] initWithFrame:rect];
label.font = [UIFont systemFontOfSize:[UIFont smallSystemFontSize]];
label.text = sel_obj->start_time;
label.backgroundColor = [UIColor redColor];
[xib_label addSubview:label];将backgroundColor更改为红色,以便清楚地看到标签。
如果你想在一个标签中显示多行,你可以:label.numberOfLines = 0;。
发布于 2013-01-09 15:10:04
您也可以在上面的注释之后尝试将子视图带到前面的[xib_lable bringSubViewToFront:label];
https://stackoverflow.com/questions/14228688
复制相似问题