我正在尝试将我的应用程序转换为Swift语言.
我有这行代码:
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]
setTitleTextAttributes:textDictionary
forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
如何将其转换为Swift?
在Apple的文档中,没有这样的方法.
我想在iOS 8中的UISearchBar中的"取消"按钮的"取消"中更改文本.我正在使用UISearchController.我尝试过iOS 6和iOS 7的不同方法,但它们不起作用.有人这样做过吗?
我添加了一个UISearchBar到我的顶部PFQueryTableViewController.我已将searchBar的颜色更改为我的应用程序的颜色,但在执行此操作时,它似乎也将其右侧的"取消"按钮的颜色更改为相同的颜色.理想情况下,我希望颜色为白色.
此图显示了当前的外观:
它看起来没有"取消"按钮,但它有与searchBar相同的颜色(你仍然可以按它等)
有没有办法让我将这个'取消按钮的颜色改为白色?我尝试的一切似乎没有任何区别.
代码我用来制作UISearchBar这种颜色是:
UISearchBar.appearance().barTintColor = UIColor(hue: 359/360, saturation: 67/100, brightness: 71/100, alpha: 1)
UISearchBar.appearance().tintColor = UIColor(hue: 359/360, saturation: 67/100, brightness: 71/100, alpha: 1)
Run Code Online (Sandbox Code Playgroud)
在故事板中我设置了这些:
最后,为了在SearchBar中制作占位符和文本白色,我使用了:
for subView in self.filmSearchBar.subviews {
for subsubView in subView.subviews {
if let searchBarTextField = subsubView as? UITextField {
searchBarTextField.attributedPlaceholder = NSAttributedString(string: NSLocalizedString("Search Cinevu film reviews", comment: ""), attributes: [NSForegroundColorAttributeName: UIColor.whiteColor()])
searchBarTextField.textColor = UIColor.whiteColor()
}
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!:)
在我的iOS5 iPhone应用程序中,我使用以下代码设置搜索栏的色调:
searchBar.tintColor = UIColorMake(@"#EFEFEF");
Run Code Online (Sandbox Code Playgroud)
#efefef的RGB值是(239,239,239)
它的工作正常.但是当出现取消按钮时,文本"取消"不可见.我可以自定义带有透明黑白文本的取消按钮吗?
可以自定义吗?
我们如何更改搜索控制器中取消按钮的标题?

我正在使用下面的代码.它在IOS 6.x中运行良好.从Xcode 4.6.x构建.但是该代码在xcode 5.x构建的IOS 7.x中不再起作用.
我的目标是当用户在UISearchBar中开始编辑时显示自定义图像来代替UISearchBar的取消按钮.
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
[searchBar setShowsCancelButton:YES animated:YES];
UIButton *cancelButton = nil;
for(UIView *subView in searchBar.subviews){
if([subView isKindOfClass:UIButton.class]){
cancelButton = (UIButton*)subView;
}
}
[cancelButton setTintColor:[UIColor colorWithRed:167.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:1.0f]];
[cancelButton setBackgroundImage:[UIImage imageNamed:@"customKeyboardIcon.png"] forState:UIControlStateNormal];
[cancelButton setTitle:nil forState:UIControlStateNormal];
}
Run Code Online (Sandbox Code Playgroud) ios ×6
swift ×3
uisearchbar ×3
ios7 ×1
ios8 ×1
searchbar ×1
uiappearance ×1
uitableview ×1
xcode5 ×1