改变按钮的文字和iOS中禁用按钮 [英] change text of button and disable button in iOS

查看:100
本文介绍了改变按钮的文字和iOS中禁用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何改变按钮的文字和iOS中禁用按钮?

How do you change the text of the button and disable a button in iOS?

推荐答案

嘿Namratha,
如果你问有关更改文本并启用一个UIButton /停用状态,就可以轻松完成pretty如下:

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;

[myButton setTitle:@"Normal State Title" forState:UIControlStateNormal]; // To set the title
[myButton setEnabled:NO]; // To toggle enabled / disabled

如果您在界面生成器中创建的按钮,并希望访问这些code,你可以利用一个事实,即它们传递作为参数传递给 IBAction为呼叫:

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:

- (IBAction) triggerActionWithSender: (id) sender;

这可以绑定到该按钮,并触发动作时,你会得到在发送按钮参数。如果这还不够(因为你需要访问按钮其他地方比在行动),申报出口的按钮:

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:

@property(retain) IBOutlet UIButton *someButton;

然后,它可以将按钮IB绑定到控制器,NIB加载code将在加载界面时设置的属性值。

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.

这篇关于改变按钮的文字和iOS中禁用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆