gpt4 book ai didi

ios - 更改以编程方式创建的 UISearchBar 的字体

转载 作者:行者123 更新时间:2023-11-28 19:08:29 25 4
gpt4 key购买 nike

我发现我的 AppDelegate 中的代码:

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil]
setFont:[UIFont systemFontOfSize:14]];

用于更改从 IB 创建的 UISearchBar 的字体。那里没有问题。

但是,如果我在这样的代码中创建 UISearchBar:

UISearchBar *bar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
bar.placeholder = @"test";
[self.view addSubview:bar];

那么上面的UITextField外观代码就没有作用了。有没有办法更改以编程方式创建的 UISearchBar 的字体?

谢谢!

最佳答案

试试这个,它适用于 iOS 5.0 及更高版本:(也适用于 iOS 7)

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setFont:[UIFont fontWithName:@"League Gothic" size:20]];

关于ios - 更改以编程方式创建的 UISearchBar 的字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18070549/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com