0

我正在使用此代码创建一个 UIButton,但是当按下按钮时,字体不会改变颜色。

_gameSlider = [UIButton buttonWithType:UIButtonTypeCustom];
    [_gameSlider setBackgroundImage:[[UIImage imageNamed:@"sliderBackgroundSticker"] resizableImageWithCapInsets:UIEdgeInsetsMake(22, 16, 22, 16)] forState:UIControlStateNormal];
    _gameSlider.frame = CGRectMake(0, 0, self.view.frame.size.width - 20, 70);
    newCnt = self.view.center;
    newCnt.y = newCnt.y + 120;
    _gameSlider.center = newCnt;
    [_gameSlider setTitle:@"PLAY" forState:UIControlStateNormal];
    [_gameSlider.titleLabel setFont:[UIFont fontWithName:@"Chalkduster" size:22]];
    [_gameSlider setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [_gameSlider setTitleColor:[UIColor yellowColor] forState:UIControlStateSelected | UIControlStateHighlighted];
    [_gameSlider addTarget:self action:@selector(playButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_gameSlider];
4

1 回答 1

2

将您想要的背景颜色放在 forState:Highlighted 下。

当它被按下时,它不在UIControlStateNormal它的UIControlStateHighlighted.

于 2012-09-21T20:56:49.757 回答