Set UIButton text

↘锁芯ラ 提交于 2019-12-12 01:35:35

问题


It is my text label:

@property (strong, nonatomic) IBOutlet UILabel *textEmail;


 _titleGet = [_dictionaryGeter objectForKey:@"Email"];
    _textEmail.text= _titleGet;

objectForKey:@"Email" from plist

I want to make button. How to make that button title to be equal to the textEmail?


回答1:


There are two ways to set the title of a UIButton.

Option 1 (the wrong way): myButton.titleLabel.text = myString

Option 2 (the right way): [myButton setTitle:myString forState:UIControlStateNormal];

So, your code would be:

_titleGet = [_dictionaryGeter objectForKey:@"Email"];
[_btn setTitle:_titleGet forState:UIControlStateNormal];



回答2:


To change a buttons text is pretty much the same

@property (strong, nonatomic) IBOutlet UIButton *buttonEmail;


_titleGet = [_dictionaryGeter objectForKey:@"Email"];
_textEmail.text= _titleGet;

buttonEmail.text =  _titleGet;



回答3:


Your code is great just a small bug i found: Just change

_textEmail.text= _titleGet;

to

_textEmail.titleLabel.text= _titleGet;



回答4:


Try This

_titleGet = [_dictionaryGeter objectForKey:@"Email"];

 NSString *valueToSave = _titleGet
[[NSUserDefaults standardUserDefaults] setObject:valueToSave forKey:@"keyYourChoice"];
[[NSUserDefaults standardUserDefaults] synchronize];


NSString *xyx = [[NSUserDefaults standardUserDefaults]
stringForKey:@"keyYourChoice"];

 _textEmail.text= xyx;

THANK YOU



来源:https://stackoverflow.com/questions/35679480/set-uibutton-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!