【发布时间】:2020-03-16 12:21:05
【问题描述】:
我尝试在 UIAlertController 中显示地图图标,但是当图像没有透明背景时,我会得到填充灰色
let customView = UIView()
// customView.translatesAutoresizingMaskIntoConstraints = false
customView.backgroundColor = .clear
customView.addConstraint(NSLayoutConstraint(item: customView,
attribute: .height,
relatedBy: .equal,
toItem: nil,
attribute: .notAnAttribute,
multiplier: 1,
constant: 100))
var marginBtns:CGFloat = 10
if yandexMap {
let yandexBtn = UIButton()
yandexBtn.frame = CGRect(x: marginBtns, y: margin, width: 30, height: 30)
yandexBtn.setImage(UIImage(named: "yandex")?.withRenderingMode(.alwaysOriginal), for: .normal)
yandexBtn.sizeToFit()
yandexBtn.imageView!.layer.cornerRadius = 5
urlYandexAction = urlYandex
yandexBtn.addTarget(self, action: #selector(actionYandexBtn), for: .touchUpInside)
marginBtns += 70
customView.addSubview(yandexBtn)
//alert.addAction(alertYandex)
}
...
let alert = UIAlertController(title: "Open in",
customView: customView,
fallbackMessage: "",
preferredStyle: .actionSheet)
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
present(alert, animated: true)
但我明白了
它不是原始图像颜色,我该如何解决?
【问题讨论】:
-
我不是 100% 确定,但这可能与 this answer 中提到的错误有关
-
@Frakcool 我如何为这个问题申请答案?我需要图像的透明色调和另一个 vc 的默认色调
-
Idk,我发现了这个相关问题,并认为它可能对你有用,试一试,如果它有效,那么我们可以想出一个解决方法
标签: swift