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 の下に置きます。

押している間は入っていませUIControlStateNormalUIControlStateHighlighted

于 2012-09-21T20:56:49.757 に答える