的UIButton +的setSelected

时间:2009-10-06 07:30:42

标签: iphone uibutton

我在我的项目中实现了以下代码!

UIImage *add_item_icon = [UIImage imageNamed:@"add_item_icon.png"];         
UIImage *img = [UIImage imageNamed:@"add_button.png"];
if(headerButton != nil)
    [headerButton release];
headerButton = [[UIButton alloc] init];
headerButton.frame = CGRectMake(0, 0, 320, 42);
headerButton.backgroundColor = [UIColor clearColor];
headerButton.showsTouchWhenHighlighted = YES;
[headerButton setBackgroundImage:img forState:UIControlStateNormal];
[headerButton setTitle:@"Add New Gallery" forState:UIControlStateNormal];
[headerButton setImage:add_item_icon forState:UIControlStateNormal];
headerButton.titleLabel.font = [UIFont systemFontOfSize:16];
headerButton.titleLabel.textColor = [UIColor darkGrayColor];
[headerButton addTarget:self action:@selector(headerButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
//[headerButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateSelected];

我的问题是每当我点击按钮时,分配给标题的颜色都已更改。要求是不应该那样。任何人都指导我!尽可能早。

1 个答案:

答案 0 :(得分:0)

不确定你的-headerButtonClicked:中有什么,但是你应该在-headerButtonClicked中删除任何看起来像这样的东西:

headerButton.titleLabel.textColor = [UIColor darkGrayColor];