1 在xcode、iphone中标记多个UILabels

发布于 2024-10-30 23:49:45 字数 133 浏览 4 评论 0原文

因此,我的应用程序中有许多包含相同文本的标签。我正在对它们进行本地化,并且想知道我是否可以用相同的数字标记它们并以这种方式分配新文本。

目前,当我测试时,它仅识别带有标签的第一个标签。

我真的很想让自己摆脱这些重复的出口

So I have many labels in my app that contain the same text. I am localizing them, and would like to know if its possible for me to tag them all with the same number and assign the new text that way.

currently when I have tested it only recognizes the first label with the tag.

I really want to save myself from having all these repeat outlets

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初见终念 2024-11-06 23:49:45

是的,

您可以用整数标记它们,因为在继承树中 NSObjectUIView 的超类,

并且 NSObject 有一个名为的整数属性标签

使用如下标签

myLabel1.tag = 1;
myLabel2.tag = 2;
...........
...........
myLabeln.tag = n;

Yes,

You can tag them with a integer number because in inheritance tree NSObject is the super class to UIView,

And NSObject has an integer property called tag .

USE tag like below

myLabel1.tag = 1;
myLabel2.tag = 2;
...........
...........
myLabeln.tag = n;
早茶月光 2024-11-06 23:49:45

从您的问题来看,您的问题是什么,但我假设您希望能够使用相同的文本更新位于应用程序内不同位置的所有 UILabel。

您可以创建一个全局头文件,其中包含一个 NSString,它保存所有标签的文本,然后在所有包含需要显示此文本的标签的视图控制器中 #include 这个头。然后,每当您更新全局标头中的 NSString 时,您都会更新当前正在查看或即将查看的所有标签。这可以在您的 IBAction 方法中完成,也可以实现 viewWillAppear:(BOOL)animated 方法。每当包含相关标签的视图进入视图时,它将应用全局标头中的 NSString 值并更新其标签。

It is a little inclear from your question what your problem is, but I am assuming from your question that you want to be able to update all your UILabels which are located at different places within your app with the same text.

You could create a global header file that contains an NSString which holds the text for all your labels, and then #include this header in all view controllers which contain labels which need to show this this text. Then whenever you update the NSString in the global header you update any labels that are currently in view or about to be viewed aswell. This can be done from within your IBAction methods, as well as implimenting the viewWillAppear:(BOOL)animated method. Whenever a view that contains relevent labels comes into view, it will apply the value of the NSString in your global header and update its labels.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文