0
let alert = UIAlertController(title: "Breaking Point Stack", message: "What's the average breaking point stack you have?", preferredStyle: UIAlertControllerStyle.alert)
alert.addTextField() { textField in
textField.backgroundColor = UIColor.clear
textField.useUnderLine()
}
self.present(alert, animated: true, completion: nil)
文本字段預期不顯示背景顏色和在底部的白線,但是,提出警告控制器時,文本字段的背景仍然是白色與黑色邊框。改變UIAlertController文本框的背景顏色不起作用
下面是useUnderLine()
代碼:
func useUnderLine() {
self.borderStyle = .none
self.layoutIfNeeded()
let border = CALayer()
let width = CGFloat(1.0)
border.borderColor = UIColor.white.cgColor
border.frame = CGRect(x: 0, y: self.frame.size.height - width, width: self.frame.size.width, height: width)
border.borderWidth = width
self.layer.addSublayer(border)
self.layer.masksToBounds = true
}
如果您確實想要更改默認的UIAlertController背景色,@ bubuxu answer是正確的。但是你真的不應該那樣做,因爲當Apple推出新的更新時,你有機會打破你的代碼。做到這一點的最佳方法是創建您自己的警報控制器。 –