gpt4 book ai didi

ios - 如何在 swift 4 中隐藏 SexyTooltip?

转载 作者:行者123 更新时间:2023-11-28 14:33:58 24 4
gpt4 key购买 nike

我正在尝试在我的 swift 项目中使用 SexyTooltip。我有这段代码:

func showTooltip(prefix: Int?){
var description = ""

description = setProductIconTitle(prefix: prefix)

let myAttribute = [ NSAttributedStringKey.foregroundColor: UIColor.black, NSAttributedStringKey.backgroundColor: .white]
let greetingsText = NSAttributedString(string: description, attributes: myAttribute)

let greetingsTooltip = SexyTooltip(attributedString: greetingsText, sizedTo: view, withPadding: UIEdgeInsetsMake(10, 5, 10, 5), andMargin: UIEdgeInsetsMake(20, 20, 20, 20))
greetingsTooltip?.dismiss(inTimeInterval: 2)
view.addSubview(greetingsTooltip!)

greetingsTooltip?.present(from: iconView1, in: view, withMargin: 10, animated: true)
}

这段代码工作正常。我想一次只看到一个提示/工具提示。单击另一个按钮后 - 所有以前的提示/工具提示都必须隐藏。

怎么做?

最佳答案

试试这个

func showTooltip(prefix: Int?){

for toolView in view.subviews {
if toolView is SexyTooltip {
toolView.removeFromSuperview()
}
}
var description = ""
description = setProductIconTitle(prefix: prefix)
let myAttribute = [ NSAttributedStringKey.foregroundColor: UIColor.black, NSAttributedStringKey.backgroundColor: .white]
let greetingsText = NSAttributedString(string: description, attributes: myAttribute)

let greetingsTooltip = SexyTooltip(attributedString: greetingsText, sizedTo: view, withPadding: UIEdgeInsetsMake(10, 5, 10, 5), andMargin: UIEdgeInsetsMake(20, 20, 20, 20))
greetingsTooltip?.dismiss(inTimeInterval: 2)
view.addSubview(greetingsTooltip!)

greetingsTooltip?.present(from: iconView1, in: view, withMargin: 10, animated: true)
}

关于ios - 如何在 swift 4 中隐藏 SexyTooltip?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51040384/

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