设置UIButton文本

时间:2016-02-28 06:22:56

标签: objective-c xcode text uibutton uilabel

这是我的文字标签:

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


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

objectForKey:来自plist的“电子邮件”

我想制作按钮。如何使该按钮标题等于textEmail?

4 个答案:

答案 0 :(得分:0)

要更改按钮文字几乎相同

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


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

buttonEmail.text =  _titleGet;

答案 1 :(得分:0)

有两种方法可以设置UIButton的标题。

选项1(错误方式): myButton.titleLabel.text = myString

选项2(正确方式): [myButton setTitle:myString forState:UIControlStateNormal];

所以,你的代码是:

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

答案 2 :(得分:0)

你的代码很棒我发现的一个小错误: 只需改变

_textEmail.text= _titleGet;

_textEmail.titleLabel.text= _titleGet;

答案 3 :(得分:0)

试试这个

_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;

谢谢你