本地化IOS按钮标签 [英] Localize IOS button label

查看:100
本文介绍了本地化IOS按钮标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用本地化字符串来本地化UI元素。一切正常,除了本地化按钮的标题。

I use localization strings to localize UI elements. Everything works, except localizing title of a button.

21.title=它应该是本地化的文本; //不起作用

"21.title" = "It should be the localized text"; //does not work

我认为这是由按钮状态(... forState:UIControlStateNormal ...)引起的,标题可以通过视图状态设置。如何在本地化文件中对其进行修改?

I think it would be caused by state of button (...forState:UIControlStateNormal...), title can be set by view state. How can I defie it in the localization file?

如何在本地化字符串中定义按钮标题?诀窍是什么?

How can I define button title in localization string? What is the trick?

注意:我知道如何从源代码中执行此操作,我的问题是如何通过本地化字符串文件来完成。所以:我知道如何使用本地化字符串来本地化UI,除了按钮。

推荐答案

在Interface Builder中,你可以设置4个字符串,一个用于状态配置下拉列表中的每个状态。

In Interface Builder, you can set 4 strings, one for each of the states in the "State Config" dropdown.

或者,在代码中,为每个状态设置按钮标题:

OR, alternatively, in code, you set the button title for each state:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:NSLocalizedString(@"21.title", @"Norm!") forState:UIControlStateNormal];
[button setTitle:NSLocalizedString(@"21.title-highlighted", @"hi btn") forState:UIControlStateHighlighted];
[button setTitle:NSLocalizedString(@"21.title-selected", @"sel btn") forState:UIControlStateSelected];
[button setTitle:NSLocalizedString(@"21.title-disabled", @"dis btn") forState:UIControlStateDisabled];

编辑:要清楚,您需要将本地化字符串添加到中Localizable.strings 文件。只要您将其复制到您的应用程序中,您就可以获得替换;当然,你可以支持多种语言。 本地化教程在IB中本地化

To be clear, you'll add the localization strings into your Localizable.strings file. As long as you copy that into your app, you'll get the substitution; and of course you can support multiple languages. Localization Tutorial and Localize in IB

这篇关于本地化IOS按钮标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆