因此,我对此iPad业务很陌生,并且基于XML文件的内容以编程方式在scrollview中创建了一些按钮。我有这样的代码上进行:iPad - 以编程方式将文本设置为按钮
float x = (SLIDER_ELEMENT_HEIGHT * i) + 20;
CGRect frame = CGRectMake(x, 0, SLIDER_ELEMENT_WIDTH, SLIDER_ELEMENT_HEIGHT);
UIButton *button = [[UIButton alloc] initWithFrame:frame];
UIColor *bgColor = [[UIColor alloc] initWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
button.backgroundColor = bgColor;
NSString *titleForButton = [NSString stringWithFormat: @"This is my title"];
[button setTitle:titleForButton forState:(UIControlStateNormal | UIControlStateApplication | UIControlStateHighlighted)];
UIColor *fgColor = [[UIColor alloc] initWithRed:0.5 green:0.5 blue:0.5 alpha:1.0];
[button setTitleColor:fgColor forState:(UIControlStateNormal | UIControlStateApplication | UIControlStateHighlighted)];
[button addTarget:self action:@selector(buttonMethod:) forControlEvents:(UIControlEvents)UIControlEventTouchDown];
[scrl_lastIssues addSubview:button];
现在,方法听者,我追加的工作正常,但按钮的文字一直没有出现什么......我做错了?
感谢您的帮助!
谢谢,这解决了我的问题!我刚刚看到一个论坛,他们用这条线来设置文本。 – 2010-07-09 16:56:32