How do you change the text of the button and disable a button in iOS?
相关问题
- Core Data lightweight migration crashes after App
- React Native Inline style for multiple Text in sin
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- 放在input的text下文本一直出现一个/(即使还没输入任何值)是什么情况
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
Use
UIControlStateNormal
to set your title.There are couple of states that UIbuttons provide, you can have a look:
In Swift 3, you can simply change the title of a button by:
and you disable the button by:
.normal
is the same asUIControlState.normal
because the type is inferred.To Change Button title:
For Disable:
Assuming that the button is a
UIButton
:See the documentation for
UIButton
.If you want to change the title as a response to being tapped you can try this inside the IBAction method of the button in your view controller delegate. This toggles a voice chat on and off. Setting up the voice chat is not covered here!
}
voiceChat is specific to voice chat of course, but you can use your ow local boolean property to control the switch.
Hey Namratha, If you're asking about changing the text and enabled/disabled state of a UIButton, it can be done pretty easily as follows;
If you have created the buttons in the Interface Builder and want to access them in code, you can take advantage of the fact that they are passed in as an argument to the
IBAction
calls:This can be bound to the button and you’ll get the button in the
sender
argument when the action is triggered. If that’s not enough (because you need to access the buttons somewhere else than in the actions), declare an outlet for the button:Then it’s possible to bind the button in IB to the controller, the NIB loading code will set the property value when loading the interface.