반응형
Swift Xcode 6의 버튼 텍스트를 변경하는 방법
이게 내가 하려는 일이야.만약 당신이 헤일로나 CoD를 해본 적이 있다면, 당신은 무기 방출의 이름을 바꿀 수 있다는 것을 알 것이다.
텍스트 필드를 사용하여 출력 이름을 변경할 수 있도록 만들고 있습니다.문제는 다음과 같습니다. Loadout 메뉴의 Loadout 이름은 버튼(Loadout에 대한 정보를 선택하고 보기 위한 것)이며, 다음과 같이 쓸 수 있습니다.
@IBAction func renameClassButton(sender: AnyObject) {
classTopButton.text = "\(classTopTextField)"
}
단, [classTopButton]는 '.text' 접미사를 사용할 수 없는 버튼입니다.
다음 작업을 수행할 수 있습니다.
button.setTitle("my text here", forState: .normal)
Swift 3, 4, 5:
button.setTitle("my text here", for: .normal)
Xcode 8 - Swift 3의 경우:
button.setTitle( "entertext" , for: .normal )
이제 스위프트3를 위해
let button = (sender as AnyObject)
button.setTitle("Your text", for: .normal)
(변수의 계속적인 선언은 필요 없습니다.버튼의 송신자를 다음과 같이 사용해 주세요.
(sender as AnyObject).setTitle("Your text", for: .normal)
이것은 버튼의 IBAtion 내에서 사용됩니다.
주의:
선
someButton.setTitle("New Title", forState: .normal)
제목 유형이 일반인 경우에만 작동합니다.
3개뿐만 아니라 4개의 작업도 신속합니다.
libero.setTitle("---", for: .normal)
여기서 libero는 의부톤이다.
sender 인수를 사용할 수 있습니다.
@IBAction func TickToeButtonClick(sender: AnyObject) {
sender.setTitle("my text here", forState: .normal)
}
Swift 4에서는 이전에 이 모든 것을 시도했지만, 다음과 같이만 실행됩니다.
@IBAction func myButton(sender: AnyObject) {
sender.setTitle("This is example text one", for:[])
sender.setTitle("This is example text two", for: .normal)
}
NSButton을 사용하는 경우,setTitle
펑크가 아니라 재산이에요
@IBOutlet weak var classToButton: NSButton!
. . .
classToButton.title = "Some Text"
언급URL : https://stackoverflow.com/questions/26641571/how-to-change-button-text-in-swift-xcode-6
반응형
'programing' 카테고리의 다른 글
Openpyxl - Python에서 Excel 파일에서 하나의 열만 읽는 방법은 무엇입니까? (0) | 2023.04.13 |
---|---|
Bash 스크립트 파라미터 (0) | 2023.04.13 |
powershell - 파일 이름과 확장자를 추출합니다. (0) | 2023.04.13 |
통합 보안 = True와 통합 보안 = SSPI의 차이점은 무엇입니까? (0) | 2023.04.13 |
Excel 번호 형식:"-409"가 뭐죠? (0) | 2023.04.13 |