ios - 样式化现有的 UITextField

标签 ios iphone objective-c cocoa-touch uitextfield

所以我在 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/

相关文章:

ios - 如何清除不指向自己代码的废弃内存?

android - 是否可以获取已安装应用程序的用户名和密码?

ios - 是否有可能在设备上安装 iOS 应用程序后将资源加载到它?

objective-c - 当现代运行时或自动合成的属性不可用时中止编译

ios - 在 Swift 中使用 Facebook 自定义登录获取用户信息

ios - 如何在 tvOS 应用程序中设置音量控制?

ios - 在 "display"MOC 中更改 NSManagedObject 时在 "scratchpad"MOC 中更新它们

iphone - 委托(delegate)方法如何知道何时被调用

IOS Storyboard : Load Multiple Subviews for given position

objective-c - iOS NSMutableData *data = [[NSMutableData alloc] init];崩溃