gpt4 book ai didi

ios - 带有白色边框的 alertController

转载 作者:搜寻专家 更新时间:2023-10-31 22:56:55 24 4
gpt4 key购买 nike

我创建了一个带有操作表和两个按钮的警报 Controller 。由于操作表将具有圆角边缘,因此在屏幕上的四个角上会出现白色。我尝试更改 alertcontroller 的背景颜色,但这是将操作表制作为具有锐边而不是圆形边框的矩形。我尝试将 View 背景颜色设置为清除颜色也尝试设置边界半径。这是我的行动表。我希望那些白色边缘不可见。

enter image description here

另外,如何更改取消的背景颜色。

let cancelAction = UIAlertAction(title: "Cancel".localize(), style: .cancel) { _ in
// this is where I am creating the cancelAction
}

编辑 - 1:为 alertcontroller 添加代码

func showActionSheet(_ changeAction: UIAlertAction) {
let alertController = UIAlertController(title: "", message: "Here is my alert text".localize(), preferredStyle: .actionSheet)

alertController.view.tintColor = StyleKit.goldenColor
let attributedString = NSAttributedString(string: alertController.message!, attributes: [
NSForegroundColorAttributeName : StyleKit.whiteColor
])
alertController.setValue(attributedString, forKey: "attributedMessage")
if let subview = alertController.view.subviews.first, let alertContentView = subview.subviews.first {
for innerView in alertContentView.subviews {
innerView.backgroundColor = StyleKit.popoverDefaultBackgroundColor

}

}
let cancelAction = UIAlertAction(title: "Cancel".localize(), style: .cancel) { _ in
self.doneButton.isEnabled = true
}

alertController.addAction(changeAction)
alertController.addAction(cancelAction)
self.present(alertController, animated: true)
}

最佳答案

这里是UIAlertAction actionSheet这个白边的解决方法

let actionSheet = UIAlertController.init(title: nil, message: nil, preferredStyle: .actionSheet)

if let subview = actionSheet.view.subviews.first, let actionSheet = subview.subviews.first {
for innerView in actionSheet.subviews {
innerView.backgroundColor = .purple
innerView.layer.cornerRadius = 15.0
innerView.clipsToBounds = true
}
}

actionSheet.addAction(UIAlertAction.init(title: "Take Photo", style: UIAlertActionStyle.default, handler: { (action) in

}))
actionSheet.addAction(UIAlertAction.init(title: "Choose Photo", style: UIAlertActionStyle.default, handler: { (action) in

}))
actionSheet.addAction(UIAlertAction.init(title: "Cancel", style: UIAlertActionStyle.cancel, handler: { (action) in
}))

actionSheet.view.tintColor = .orange

self.present(actionSheet, animated: true, completion: nil)

用十六进制颜色更新

Github : https://github.com/BhaveshDhaduk/AlertControllerSwift

enter image description here

关于ios - 带有白色边框的 alertController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44719277/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com