2016-09-15 36 views
0

我有幾個文本框在我的視圖控制器,我創建了他們的自定義類:自定義文本框不改變默認的外觀

class CustomTextField: UITextField { 

required init?(coder aDecoder: NSCoder) { 
    super.init(coder: aDecoder) 

    self.layer.cornerRadius = 15.0; 
    self.layer.borderWidth = 1.5 
    self.layer.borderColor = UIColor.white.cgColor 

    self.backgroundColor = UIColor.black 
    self.textColor = UIColor.white 
} 
} 

在我的視圖控制器,創建這樣的網點:

@IBOutlet weak var itemCountTextField: CustomTextField! { didSet { itemCountTextField.delegate = self } } 

但是當我運行它時,UITextFields仍然看起來像默認的白色文本字段,定製沒有完成,我在哪裏做錯了?

+0

我覺得你需要設置其他類型的邊框樣式才能脫離默認樣式 – Tj3n

+0

@ Tj3n我剛剛嘗試過,似乎並不是這樣,再加上它似乎在這個問題上工作得很好:http:// stackoverflow .COM /問題/ 29888253 /轉換自定義文本字段,背景顏色和字體顏色,IOS-迅速 –

回答

0

您設置的UITextField子類是CustomTextField &隨後的作品...

enter image description here

0

確保你的文本框類設置爲CustomTextField也是你的情節提要/ XIB,只是改變了插座類型是不夠的。