xcode 如何更改 UINavigationBar 中的“编辑/完成”按钮标题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13429743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change Edit/Done button title in UINavigationBar
提问by aLFaRSi
If Editing mode is enabled for the tableview it shows a button titled Edit, when pressing it it changes the title to done
如果为 tableview 启用了编辑模式,它会显示一个标题为“编辑”的按钮,按下它时会将标题更改为完成
i was wondering if there is a way to change the Done Button title to something else ?
我想知道是否有办法将完成按钮标题更改为其他内容?
i already changed the title for the done button.
我已经更改了完成按钮的标题。
the code i used is
我使用的代码是
self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.editButtonItem.title = @"Change";
Now The Edit is Change
现在编辑是变化
How to make Done to something else ?
如何完成其他事情?
采纳答案by Nitin Gohel
You can change the title of the edit button like this:-
您可以像这样更改编辑按钮的标题:-
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
// Make sure you call super first
[super setEditing:editing animated:animated];
if (editing)
{
self.editButtonItem.title = NSLocalizedString(@"Cancel", @"Cancel");
}
else
{
self.editButtonItem.title = NSLocalizedString(@"Edit", @"Edit");
}
}
its working like edit:-
它的工作方式就像编辑:-
TO
到
回答by MGM
Here is the method to change it for Swift
这是为 Swift 更改它的方法
override func setEditing (editing:Bool, animated:Bool)
{
super.setEditing(editing,animated:animated)
if (self.editing) {
self.editButtonItem().title = "Editing"
}
else {
self.editButtonItem().title = "Not Editing"
}
}
回答by Benjohn
Building on Nitin's answerI suggest a slightly different approach that uses the built in UIButtonBar
system items.
基于Nitin 的回答,我建议使用一种稍微不同的方法来使用内置UIButtonBar
系统项。
This will give your UI the system look & feel. For example, the standard "Done" button to cease editing should have a specific boldlook on iOS 8. Apple might change these stylings in future. By using the system defined buttons your app will pick up the current aesthetic automatically.
这将为您的 UI 提供系统外观和感觉。例如,用于停止编辑的标准“完成”按钮在 iOS 8 上应该具有特定的粗体外观。Apple 将来可能会更改这些样式。通过使用系统定义的按钮,您的应用程序将自动选择当前的美学。
This approach also provides you with free string localisation. Apple have already translated the system button titles for you in to the dozens of languages that iOS supports.
这种方法还为您提供了免费的字符串本地化。Apple 已经为您将系统按钮标题翻译成 iOS 支持的数十种语言。
Here's the code I've got:
这是我得到的代码:
-(IBAction) toggleEditing:(id)sender
{
[self setEditing: !self.editing animated: YES];
}
-(void) setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing: editing animated: animated];
const UIBarButtonSystemItem systemItem =
editing ?
UIBarButtonSystemItemDone :
UIBarButtonSystemItemEdit;
UIBarButtonItem *const newButton =
[[UIBarButtonItem alloc]
initWithBarButtonSystemItem: systemItem
target: self
action: @selector(toggleEditing:)];
[self.navigationItem setRightBarButtonItems: @[newButton] animated: YES];
}
The example here is for the case where your UIViewController
is hosted in a UINavigationController
and so has a UINavigationItem
instance. If you're not doing this, you'll need to update the bar item in an appropriate way.
此处的示例适用于您UIViewController
托管在 a 中UINavigationController
并因此有一个UINavigationItem
实例的情况。如果您不这样做,则需要以适当的方式更新栏项目。
In your viewDidLoad
use the following call to configure the edit button ready for use:
在您viewDidLoad
使用以下调用来配置准备使用的编辑按钮:
[self setEditing: NO animated: NO];