所以我在 Interface Builder 中有一个 UITextField
,我正在尝试更改边框。
在我的 initWithNibName
方法中,这就是我所做的 -
self.searchBar.layer.cornerRadius=8.0f;
NSLog(@"SEARCH BAR : %@", self.searchBar);
self.searchBar.layer.masksToBounds=YES;
self.searchBar.layer.borderColor=[[UIColor redColor]CGColor];
self.searchBar.layer.borderWidth= 1.0f;
这不起作用,因为 searchBar 为空,这很奇怪,因为我在 initWithNibName 方法中。
如何更改此文本字段的边框?
最佳答案
你做得太早了。来自 UIViewController
doc :
The nib file you specify is not loaded right away. It is loaded the first time the view controller’s view is accessed. If you want to perform additional initialization after the nib file is loaded, override the viewDidLoad method and perform your tasks there.
关于ios - 样式化现有的 UITextField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20673140/