我想使用外观来设计应用程序中 AlertController 的外观。它适用于背景和按钮,但无论我尝试什么,标题和消息的标签始终保持不变...
我想使用外观来设计应用程序中 AlertController 的外观。它适用于背景和按钮,但无论我尝试什么,标题和消息的标签始终保持黑色。
以下是我正在做的事情:
UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = .orange
UIVisualEffectView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).effect = UIBlurEffect(style: .dark)
UILabel.appearance(whenContainedInInstancesOf: [UIAlertController.self]).textColor = .white
这是我得到的结果:
有什么想法,我该如何设置标题和消息的颜色,或者为什么在这种情况下更改 UILabel 的外观不起作用?
您可以尝试一下这个代码吗?
class WebSocketManager: NSObject, URLSessionWebSocketDelegate {
private var webSocketTask: URLSessionWebSocketTask!
private lazy var urlSession: URLSession = {
let configuration = URLSessionConfiguration.default
return URLSession(configuration: configuration, delegate: self, delegateQueue: OperationQueue())
}()
private var urlRequest: URLRequest {
var request = URLRequest(url: ApiUrl.socket.url)
request.allHTTPHeaderFields = [
"login" : "****",
"passcode" : "****",
"host" : "/",
"accept-version" : "****"
]
return request
}
override init() {
super.init()
webSocketTask = urlSession.webSocketTask(with: urlRequest)
}
func connect() {
webSocketTask.resume()
}
}
您需要对您的问题进行更多调试。
extension WebSocketManager {
func send(message: String) {
let message = URLSessionWebSocketTask.Message.string(message)
webSocketTask.send(message) { error in
if let error = error {
print("WebSocket sending error: \(error)")
}
}
}
func receive() {
webSocketTask.receive { [weak self] result in
switch result {
case .failure(let error):
print("WebSocket receiving error: \(error)")
case .success(let message):
switch message {
case .string(let text):
print("Received text: \(text)")
case .data(let data):
print("Received data: \(data)")
@unknown default:
fatalError()
}
self?.receive()
}
}
}
func disconnect() {
webSocketTask.cancel(with: .goingAway, reason: nil)
}
}