【发布时间】:2011-10-18 11:58:19
【问题描述】:
我正在创建一个 iPhone 应用程序,其中有一个自定义按钮。我通过创建标签并将其添加为子视图来设置按钮标题。现在,当按钮突出显示时,我想更改标签文本颜色。
这是我的代码,
UIButton *button1= [UIButton buttonWithType:UIButtonTypeCustom];
[button1 setFrame:CGRectMake(68,162, 635, 101)];
[button1 setImage:[UIImage imageNamed:@"startwithouttext.png"] forState:UIControlStateNormal];
[button1 setImage:[UIImage imageNamed:@"startactivewithouttext.png"] forState:UIControlStateHighlighted];
UILabel *buttonLabel = [[UILabel alloc] initWithFrame:CGRectMake(button1.bounds.origin.x+50, button1.bounds.origin.y+20, button1.bounds.size.width-100, button1.bounds.size.height-40)];
[buttonLabel setFont:[UIFont fontWithName:@"Helvetica" size:28]];
buttonLabel.backgroundColor=[UIColor clearColor];
buttonLabel.textColor=[UIColor colorWithRed:83.0/255.0 green:83.0/255.0 blue:83.0/255.0 alpha:1.0];
buttonLabel.highlightedTextColor=[UIColor whiteColor];
buttonLabel.text = @"Long text string";
[button1 addSubview:buttonLabel];
[button1 bringSubviewToFront:buttonLabel];
[button1 setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
[button1 setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
[button1 addTarget:self action:@selector(button1clicked:) forControlEvents:
[mainView button1];
当按钮被突出显示时,任何正文可以帮助我更改文本颜色吗?
【问题讨论】:
-
我可以在调用 button1clicked 方法时更改文本颜色,但我想要的是在高亮按钮时更改文本颜色
-
“当按钮突出显示时我想更改标签文本颜色”是什么意思?你的意思是什么时候点击按钮,点击之后的文字应该是原来的样子?
-
那是 UIControlStateHighlighted 我想改变文本颜色。如果您当时将鼠标悬停在按钮上,我想更改文本颜色
标签: iphone objective-c ipad