ios - 如何在Xcode swift中为ui标签使用if语句
问题描述
我的代码:
import UIKit
class ViewController: UIViewController {
var score = 0
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func textfield(_ sender: Any) {
}
@IBAction func Button(_ sender: Any) {
let imageName = "FB copy-3.png"
let image = UIImage(named: imageName)
let imageView = UIImageView(image: image!)
imageView.frame = CGRect(x: 64.5, y: 413.5, width: 100, height: 100); view.addSubview(imageView)
Counterlabel.text = String(score)
if score >= 500 && score <= 998 {
score += 2
imageView.image = UIImage(named:"500button")
}
else if score >= 998 && score <= 1995 {
score += 5
}
else if score >= 1995 && score <= 4000 {
score += 10
imageView.image = UIImage(named:"2000button")
}
else if score >= 4000 && score <= 10000 {
score += 20
}
else if score >= 10000 && score <= 25000 {
score += 50
}
else if score >= 25000 && score <= 75000 {
score += 100
}
else if score >= 75000{
score += 250
}
else {
score += 1
}
}
@IBAction func buttonimage(_ sender: Any) {
}
@IBOutlet weak var Counterlabel: UILabel!
}
所以我最近开始编码并且不太了解我想创建一个小游戏,这是我的问题:
我首先想在我的游戏中添加一个作弊码,所以我有一个文本标签,我想要它,这样如果我的文本标签文本是 1811(或任何有效),那么得分 += 50000
这就是我一直面临的问题
还有一件更重要的事情(如果可能的话)我真的很想知道如何保存 gtame 数据,所以如果再次播放,进度会被保存。我要保存的唯一进度是数字。
排行榜也不错
以上任何一项都会对我有帮助,我真的很感激。
这就是我的故事板的样子:
解决方案
您可以使用类似检查 textField 值
if textField.text == "11811" { socre += 5000 }
推荐阅读
- elasticsearch - 在 kibana 仪表板的 elastalert kibana 插件中创建规则
- angular - 有没有办法使用Angular路由路由到文件夹中的所有url?
- javascript - Dynamics 365 功能区按钮中带有 JS 的奇怪命名空间上下文行为
- database - 另一个efcore违反主键约束引用表的问题
- android-studio - Android Studio Flutter Project Dart 版本 confilic with flutter_localizations 依赖错误
- javascript - 选中后如何覆盖 Material-UI 开关组件的样式?
- geolocation - 使用控制点将纬度/经度坐标转换为 X、Y 平面
- html - 回退
- flutter - 同一 BLoC 事件触发次数不超过一次
- python - 如何使用 Python Altair 将 x 轴和 y 轴的交点从 0 移动到 1?