Lin*_*ink 18 iphone uibutton settext xcode4
当我从上一个视图中按下"下一步"按钮时,我正在尝试在新视图上设置UIButton的文本.我已正确设置了IBOutlet,我已经全神贯注地寻找答案,但它根本不起作用.
以下是我正在尝试做的一个示例:
- (IBAction)computeQuiz:(id)sender
{
[fiveFootUniversalResults setTitle:@"Test" forState:UIControlStateNormal];
}
- (IBAction)jumpT10ResultsView:(id)sender
{
NSString *nibFileToLoad = @"JumpT10Results";
UIDevice *device = [UIDevice currentDevice];
if([device userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
nibFileToLoad = [nibFileToLoad stringByAppendingString:@"-iPad"];
}
JumpmasterPathfinderViewController *nextView = [[JumpmasterPathfinderViewController alloc] initWithNibName:nibFileToLoad bundle:nil];
// Modal view controller
nextView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:nextView animated:YES];
[nextView release];
[scrollView setContentSize:CGSizeMake(imageViewWidth, imageViewHeight + 44.0)];
}
Run Code Online (Sandbox Code Playgroud)
这些操作都连接到上一个视图上的按钮.视图加载精细和一切,唯一的问题是文本不会在按钮上更改.我100%肯定我的IBOutlets设置正确我只是不知道我做错了什么.有任何想法吗?
Aar*_*ger 27
它不起作用,因为IB设置attributedTitle
而不是title
.
试试这个:
NSAttributedString *attributedTitle = [self.myButton attributedTitleForState:UIControlStateNormal];
NSMutableAttributedString *mas = [[NSMutableAttributedString alloc] initWithAttributedString:attributedTitle];
[mas.mutableString setString:@"New Text"];
[self.myButton setAttributedTitle:mas forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
或者,或者:
[self.myButton setAttributedTitle:nil forState:UIControlStateNormal];
[self.myButton setTitle:@"New Text" forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
(第二个选项不会保留您的格式.)
归档时间: |
|
查看次数: |
15904 次 |
最近记录: |