我正在使用此代码创建一个 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];