How to change button text in Swift Xcode 6?

Photo by Amza Andrei on Unsplash

Here’s what I’m trying to do. If you’ve ever played Halo or CoD, you’d know that you could change the name of a weapon load-out.

What I’m doing is making it so you can change your load-out name using a text field. Here’s the problem, the load-out name in the load-out menu is a button (to select and view info about that load-out) and I could just write this:

@IBAction func renameClassButton(sender: AnyObject) {
classTopButton.text = "\(classTopTextField)"
}

Except it [classTopButton] is a button which doesn’t allow the ‘.text’ suffix

The solutions is…

You can do:

button.setTitle("my text here", forState: .normal)

Swift 3 and 4:

button.setTitle("my text here", for: .normal)

check similar questions with solutions at SyntaxFix

--

--

--

Curated Solutions On Popular Questions — On All Programming Languages, Cloud Computing, Tools etc

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Swift advanced charts from scratch —  Pt 2

Decoding a JSON Field that Could Be String or Double with Swift

iOS 14.5 Data Usage and User Tracking — In-Depth Understanding

Apple fails again to help business.

Creating Markers, Pins, and Annotations in SwiftUI with iOS 14

Structures & Classes in Swift

iOS project best practices and tools

Sign in with Apple -SwiftUI

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
SyntaxFix

SyntaxFix

Curated Solutions On Popular Questions — On All Programming Languages, Cloud Computing, Tools etc

More from Medium

My Swift Studying Notes

Create a grid view in iOS using Swift Grid View (Part 1)

How to adapt your View for each device

Create your custom Media Player in MVVM (SwiftUI) — Part 1