單擊時如何更改標籤中的字母? 2個按鈕用於較小的字母或大寫。單擊時如何更改標籤中的字母?
當我們單擊小寫字母的標籤更改爲小寫字母,反之亦然。
如何做到這一點?我嘗試了一些代碼,但我被卡住了。
let ABC = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
var str: Character = "Z"
//@IBOutlet weak var capitalABC: UIButton!
// @IBOutlet weak var smallac: UIButton!
// @IBOutlet weak var Abclbl: UILabel!
@IBOutlet weak var Abclbl: UILabel!
// @IBOutlet weak var Abclbl: Le!
override func viewDidLoad() {
super.viewDidLoad()
Abclbl.text = ABC[0]
// Do any additional setup after loading the view.
}
func ABCPre(sender: AnyObject) {
if Abclbl.text == "a"
{
print("Do nothing")
}
else
{
let preVal = self.Abclbl.text!
var inde = ABC.indexOf(preVal)
inde = inde! - 1
let get = ABC[inde!]
Abclbl.text = get
alphReocg(Abclbl.text!)
}
}
func ABCNext(sender: AnyObject) {
//let str: String = "Z"
if Abclbl.text! == String(str)
{
print("Do nothing")
}
else
{
let preVal = self.Abclbl.text!
var inde = ABC.indexOf(preVal)
inde = inde! + 1
let get = ABC[inde!]
Abclbl.text = get
alphReocg(Abclbl.text!)
}
}
請澄清你的問題。您發佈的代碼到底有什麼問題? – rmaddy
是的。這個問題並不能清楚地理解 –
聽起來像你的任務的一部分涉及改變一個字符串的情況。 'String'具有['小寫()'](https://developer.apple.com/reference/swift/string/1641392-lowercased)和['大寫()'](https://developer.apple。 com/reference/swift/string/1640996-uppercased)函數。 – mattliu