gpt4 book ai didi

ios - 单击时如何更改标签中的字母?

转载 作者:行者123 更新时间:2023-11-30 12:49:30 24 4
gpt4 key购买 nike

点击时如何更改标签中的字母? 2 个用于较小字母或大写字母的按钮。

当我们单击小写字母时,标签会更改为小写字母,反之亦然。

如何做到这一点?我尝试了一些代码,但我被卡住了。

enter image description here

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!)
}
}

最佳答案

如果您需要简单地将文本转换为小写和大写,然后在按钮单击方法中转换字符串,如下所示

为swift 3.0首次导入基础

import Foundation

然后在按钮中单击操作

 func uppercase(sender: AnyObject) {

var title = "Text That you need to convert "
title.uppercased() // "TEXT THAT YOU NEED TO CONVERT"
}

对于小写

   func lowercase(sender: AnyObject) {

var title = "Text That you need to convert"
title.lowercased() // "text that you need to convert"
}

关于ios - 单击时如何更改标签中的字母?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41177229/

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