gpt4 book ai didi

ios - 快速比较按钮内的字符串

转载 作者:搜寻专家 更新时间:2023-11-01 06:22:20 25 4
gpt4 key购买 nike

我在 swift 中为我的报价应用程序实现了一个收藏夹按钮。因为我想禁止用户两次收藏报价。 我必须将文本更改为不同,然后比较按钮文本模式不同和按钮文本模式相似。然后根据这些条件做进一步的事情。它看起来像:

@IBAction func favour(sender: AnyObject) {
if liketext.text == "Like"{
liketext.setTitle("Unlike", forState: UIControlState.Normal)
makeQuoteFavourite()
} else if liketext.text == "Unlike" {

liketext.setTitle("Like", forState: UIControlState.Normal)

}
}

但是正如你们很多人所知,按钮导出不能具有 .text 功能。 @IBOutlet var liketext: UIButton! 我怎样才能将按钮字符串与普通字符串进行比较?还有其他可能的解决方案吗?

最佳答案

UIButtonUILabel 的工作方式完全不同。一方面,他们有控制状态。他们的(标题)文本可以在每个控件状态的基础上设置。

所以你必须使用 currentTitle 属性:

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIButton_Class/#//apple_ref/occ/instp/UIButton/currentTitle

titleForState 方法:

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIButton_Class/#//apple_ref/occ/instm/UIButton/titleForState :

现在这些标题普通的String对象;不同的是属性的名称。

关于ios - 快速比较按钮内的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31757195/

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