0
我在Stackoverflow上找到了指示器函數。我也喜歡它,但我無法更改文本顏色,實際上,我更改了blackColor()的代碼,但它不起作用。我如何解決它?我想看到文字和指示符都是黑色的。如何更改Swift中的文本顏色?
class ProgressHUD: UIVisualEffectView {
var text: String? {
didSet {
label.text = text
}
}
let activityIndictor: UIActivityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.White)
let label: UILabel = UILabel()
let blurEffect = UIBlurEffect(style: .Light)
let vibrancyView: UIVisualEffectView
init(text: String) {
self.text = text
self.vibrancyView = UIVisualEffectView(effect: UIVibrancyEffect(forBlurEffect: blurEffect))
super.init(effect: blurEffect)
self.setup()
}
required init(coder aDecoder: NSCoder) {
self.text = ""
self.vibrancyView = UIVisualEffectView(effect: UIVibrancyEffect(forBlurEffect: blurEffect))
super.init(coder: aDecoder)!
self.setup()
}
func setup() {
contentView.addSubview(vibrancyView)
vibrancyView.contentView.addSubview(activityIndictor)
vibrancyView.contentView.addSubview(label)
activityIndictor.startAnimating()
}
override func didMoveToSuperview() {
super.didMoveToSuperview()
if let superview = self.superview {
let width = superview.frame.size.width
let height = superview.frame.size.height
self.frame = CGRectMake(superview.frame.size.width/2 - width/2,
superview.frame.height/2 - height/2,
width,
height)
vibrancyView.frame = self.bounds
let activityIndicatorSize: CGFloat = 50
activityIndictor.frame = CGRectMake(5, height/2 - activityIndicatorSize/2,
activityIndicatorSize,
activityIndicatorSize)
layer.cornerRadius = 8.0
layer.masksToBounds = true
label.text = text
label.textAlignment = NSTextAlignment.Center
label.frame = CGRectMake(activityIndicatorSize + 5, 0, width - activityIndicatorSize - 15, height)
label.textColor = UIColor.blackColor() //I changed here grayColor() to blackColor but it doesn't work!
label.font = UIFont.boldSystemFontOfSize(16)
}
}
func show() {
self.hidden = false
}
func hide() {
self.hidden = true
}
}
什麼樣的文本只想? ? –
This one:label.text = text –
好吧,我添加了一個答案 –