is it possible to update UIButton title/text programmatically?
Do you have the button specified as an IBOutlet in your view controller class, and is it connected properly as an outlet in Interface Builder (ctrl drag from new referencing outlet to file owner and select your UIButton object)? That's usually the problem I have when I see these symptoms.
Edit: While it's not the case here, something like this can also happen if you set an attributed title to the button, then you try to change the title and not the attributed title.
Changing text of UIButton programmatically swift
In Swift 3, 4, 5:
button.setTitle("Button Title", for: .normal)
Otherwise:
button.setTitle("Button Title", forState: UIControlState.Normal)
Also an @IBOutlet
has to declared for the button
.
How to change a button's title programmatically]
Well....This is awkward but you have to set your UIButton title to Plain in storyboard to have it changed
ProfilePhoneNumberLabel.setTitle(PhoneNumbers[MyIndex], for: .normal)
+
Plain UIButton
Title
=
Happy Camper
How to change UIButton title text dynamically
Your button is dynamically attached, you must create a reference to it.
You can use a counter, like this:
-(void) aMethod{
if(ctr < arrayLength){
ctr++;
[buttonReference setText:@"Show More"];
} else {
ctr--;
[buttonReference setText:@"Return"];
}
.....
}
Programmatically change button text]
it should be like this :
For Objective C :
[_button setTitle:@"example text" forState:UIControlStateNormal];
For Swift :
_button.setTitle("example Text", forState: UIControlState.Normal)
Swift 3 changing the title of a UIButton
Your button needs to be an IBOutlet rather than an IBAction. When you ctrl-drag from Interface Builder to your code, make sure you select the 'Outlet' option as shown below:
Then you can change the button title like this:
else {
startButton.setTitle("Button Title", for: .normal)
stopFuncs = true
}
Related Topics
How to Set the Title of a Navigation Bar Programmatically
How to Use Sf Symbols in iOS 12 and Below
Objective-C Delay Action with Blocks
Why the Extension Is "Momd" But Not "Xcdatamodel" When Search the Path for the Model File
How to Set Fake Gps Location on iOS Real Device
Reload Tableview Section Without Scroll or Animation
Ios7 Uipickerview How to Hide the Selection Indicator
Transparent Uinavigationbar in Swift
How to Extract a Url from a Sentence That Is in a Nsstring
Facebook Logout Is Not Working in New Sdk V.4.1.0 in iOS
Sectionindextitles for a Uicollectionview
Capture Metal Mtkview as Movie in Realtime
How to Integrate Linphone into an Existing Project (Sip in iOS)
Populating Tableview with Multiple Sections and Multiple Dictionary in an Array in Swift
Mixing Static and Dynamic Sections in a Grouped Table View
@State Var Not Updated as Expected in Lazyvgrid
Repeat Interval for Unnotification
Uiimagepickercontroller Camera View Rotating Strangely on iOS 8 (Pictures)