Вот мой код:
override func draw(_ rect: CGRect) {
let boxWidth: CGFloat = 96
let boxHeight: CGFloat = 96
let boxRect = CGRect(x: round((bounds.size.width - boxWidth) / 2),
y: round((bounds.size.height - boxHeight) / 2),
width: boxWidth, height: boxHeight)
let roundedRect = UIBezierPath(roundedRect: boxRect, cornerRadius: 10)
UIColor(white: 0.3, alpha: 0.8).setFill()
roundedRect.fill()
if let image = UIImage(named: "Checkmark") {
let imagePoint = CGPoint(
x: center.x - round(image.size.width / 2),
y: center.y - round(image.size.height / 2) - boxHeight / 8)
image.draw(at: imagePoint)
}
let attribs = [ kCTFontAttributeName: UIFont.systemFont(ofSize: 66.0), kCTForegroundColorAttributeName: UIColor.white]
let textSize = text.size(withAttributes: attribs as [NSAttributedString.Key : Any])
let textPoint = CGPoint(
x: center.x - round(textSize.width / 2),
y: center.y - round(textSize.height / 2) + boxHeight / 4)
text.draw(at: textPoint, withAttributes: attribs as [NSAttributedString.Key : Any])
}
Цвет текста в HUD черный. Почему и как я могу изменить его на белый?





Вы можете изменить его в этой строке
let attribs = [ kCTFontAttributeName: UIFont.systemFont(ofSize: 66.0), kCTForegroundColorAttributeName: UIColor.white.CGColor]
Цвет переднего плана текста, к которому применяется этот атрибут. Значение, связанное с этим атрибутом, должно быть объектом CGColor. Значение по умолчанию — черный. Обратитесь сюда
Вы должны использовать NSAttributedString.Key вместо CoreText ключей, попробуйте заменить это:
let attribs = [ kCTFontAttributeName: UIFont.systemFont(ofSize: 66.0), kCTForegroundColorAttributeName: UIColor.white]
с этим:
let attribs: [NSAttributedString.Key: Any] = [.font: UIFont.systemFont(ofSize: 66.0),
.foregroundColor: UIColor.green]
Попробуй это:
let attribs = [NSAttributedString.Key.font.rawValue: UIFont.systemFont(ofSize: 66.0), NSAttributedString.Key.foregroundColor: UIColor.white] как! [Строка: любая]
Не связано, но есть ли причина, почему бы не использовать напрямую
let attribs: [NSAttributedString.Key: Any] = [.font: UIFont.systemFont(ofSize: 66.0), .foregroundColor: UIColor.white]вместо констант CoreText, а затем сделатьas [NSAttributedString.Key : Any]?