带有白色边框的警报控制器 [英] alertController with white borders

查看:22
本文介绍了带有白色边框的警报控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

还有,如何更改取消的背景颜色.

let cancelAction = UIAlertAction(title: "Cancel".localize(), style: .cancel) { _ in//这是我创建cancelAction的地方}

Edit - 1 : 为 alertcontroller 添加代码

func showActionSheet(_ changeAction: UIAlertAction) {let alertController = UIAlertController(title: "", message: "Here is my alert text".localize(), preferredStyle: .actionSheet)alertController.view.tintColor = StyleKit.goldenColor让attributedString = NSAttributedString(string: alertController.message!, attributes: [NSForegroundColorAttributeName : StyleKit.whiteColor])alertController.setValue(attributedString, forKey: "attributedMessage")如果让 subview = alertController.view.subviews.first,让 alertContentView = subview.subviews.first {用于 alertContentView.subviews 中的innerView {innerView.backgroundColor = StyleKit.popoverDefaultBackgroundColor}}let cancelAction = UIAlertAction(title: "Cancel".localize(), style: .cancel) { _ inself.doneButton.isEnabled = true}alertController.addAction(changeAction)alertController.addAction(cancelAction)self.present(alertController,动画:真)}

解决方案

这里是UIAlertAction actionSheet

这个白色边框的解决方案

let actionSheet = UIAlertController.init(title: nil, message: nil, preferredStyle: .actionSheet)如果让 subview = actionSheet.view.subviews.first,让 actionSheet = subview.subviews.first {用于 actionSheet.subviews 中的内视图 {内部视图.backgroundColor = .purple内部视图.layer.cornerRadius = 15.0innerView.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 = .orangeself.present(actionSheet,动画:true,完成:nil)

使用十六进制颜色更新

Github:

I have created an alertcontroller with action sheet and two buttons. As the actionsheet will be having rounded edges, on the screen, on four corners, white color is appearing. I tried changing the background color of the alertcontroller, but that is making the action sheet to rectangular with sharp border instead of rounded borders. I tried setting the view background color to clear color Tried setting the border radius too. Here is my action sheet. I want those white edges invisible.

Also, how to change the background color of Cancel.

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

Edit - 1 : Adding code for 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)
}

解决方案

here is the solution of this white border of 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)

Update with hex color

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

这篇关于带有白色边框的警报控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆