gpt4 book ai didi

iphone - 如何在 UILabel 中添加 UILabel?

转载 作者:行者123 更新时间:2023-11-29 04:12:16 28 4
gpt4 key购买 nike

这个问题看起来很平常..但是我昨天遇到了问题,我在 xib 中添加了一个标签并为其创建了导出,我想要在该标签内有多行,按钮,所以我决定添加新的子里面有标签...

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。我在这里错过了什么吗?谢谢……

最佳答案

我很久以前就遇到过这种情况。

仅供引用:

我认为问题在于 initial_rect,它位于 View 的框架中,但在 xib_label 的框架之外。label的frame是相对于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];

将背景颜色更改为红色以清晰地看到标签。

如果您想在标签中显示多行,您可以:label.numberOfLines = 0;.

关于iphone - 如何在 UILabel 中添加 UILabel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14228688/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com