简体   繁体   English

为什么我不能在iOS中更改按钮标题

[英]why cant I change button title in ios

I am new to ios, and trying to change a simple button text from implementation side in an action. 我是ios的新手,并尝试在操作中从实现方面更改简单的按钮文本。 I have tried two of these: while one of them works, the other one doesnt ! 我尝试了其中两种:虽然其中一种有效,但另一种无效!

self.Btn_Analyse.titleLabel.text = @"Stop Anlaysing";  // didnt work

And... 和...

[self.Btn_Analyse setTitle:@"Deneme" forState:UIControlStateNormal]; //worked

why doesnt the first one work? 为什么第一个不起作用? PS: I have connected the button as IBOutlet PS:我已将按钮连接为IBOutlet

Why are you telling us what worked? 您为什么要告诉我们什么有效?

If it worked then there isn't a problem. 如果有效,那就没有问题了。

Anyway, the reason the first one didn't work is because a button is not just a label. 无论如何,第一个按钮不起作用的原因是按钮不仅是标签。 It has various states and each state can have different properties. 它具有各种状态,每个状态可以具有不同的属性。

You set the image for the state. 您为状态设置图像。 You set the title for the state. 您设置状态的标题。 etc... 等等...

Then with different states you can have different properties. 然后,使用不同的状态,您可以具有不同的属性。

UIButton sets the title on its own, so if you directly change the text in label, button changes it back. UIButton自行设置标题,因此,如果直接更改标签中的文本,则button会将其改回。 That's because button can have different titles for different states (label can't do that), and sets the appropriate one automatcally. 这是因为button可以针对不同的状态使用不同的标题(label不能这样做),并自动设置相应的标题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM