如何更改 UISearchBar 字体大小 &颜色? [英] How to change UISearchBar Font Size & Color?

查看:31
本文介绍了如何更改 UISearchBar 字体大小 &颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用谷歌搜索了几个小时如何更改我的 UISearchBar 字体大小 &颜色,但我找不到任何与之相关的文档.

I've google fews hours how to change my UISearchBar font size & color, but I cannot any documents related to it.

这是我迄今为止在 swift 4 上所做的:

This is what I've done so far on swift 4:

 searchBar = UISearchBar(frame: CGRect(x: 0, y: 0, width: view.frame.width - (menuImage.frame.width + iconImage.frame.width + 55), height: 30))
 searchBar.placeholder = "SEARCH BAR"
 searchBar.tintColor = UIColor.gray
 searchBar.delegate = self
 searchBar.font = [UIFont fontWithName:@"Oswald" size:11];

但它给了我一个错误.

您能告诉我如何更改 UISearchBar 字体大小吗?颜色?

Could you tell me how can I change the UISearchBar font size & color?

请帮忙!!!

推荐答案

要更改文本和占位符搜索栏:

To change text and placeholder searchbar:

// SearchBar text
let textFieldInsideUISearchBar = searchBar.value(forKey: "searchField") as? UITextField
textFieldInsideUISearchBar?.textColor = UIColor.red
textFieldInsideUISearchBar?.font = textFieldInsideUISearchBar?.font?.withSize(12)

// SearchBar placeholder
let labelInsideUISearchBar = textFieldInsideUISearchBar!.value(forKey: "placeholderLabel") as? UILabel
labelInsideUISearchBar?.textColor = UIColor.red

这篇关于如何更改 UISearchBar 字体大小 &颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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