我的 ViewController 在顶部显示一个按钮。 该按钮是通过 Interface Builder 定义的 View 的一部分,其标签上没有任何文本。 当显示 ViewController 的 View 时,我按以下方式设置按钮的文本:
[dButton setTitle:[NSLocalizedString( @"DeleteButton", @"" ) uppercaseString] forState: UIControlStateNormal];
dButton.titleLabel.textColor = [UIColor whiteColor];
在运行时执行此操作的原因是从适当的国际化字符串文件中获取标题。上面的代码由我的 ViewController 的 viewDidAppear:animated: 方法调用,并且它在类似的 View 上按预期工作。
它不起作用的 View 是我在加载时显示 UIImagePickerController 的 View ,因此这可能是我的问题的原因:有人知道如何处理它吗? IE。如何在 UIImagePickerController 关闭后显示按钮及其文本?
--编辑
- (void)viewDidAppear:(BOOL)animated {
[self setupDeleteButton];
[super viewDidAppear:animated];
NSLog( @"Title is >%@<", dButton.titleLabel.text );
}
最佳答案
解决了! 我使用的 UIButton 已在 Interface Builder 上设置为“自定义”类型,并在“图像”属性上设置了图像,而我应该在“背景”属性上设置图像:文本实际上已添加到按钮中,但是 Image 属性覆盖了它!
关于ios - 在 UIButton 上显示一些动态文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8069886/