gpt4 book ai didi

ios - UIButton 自定义按钮不会在选择时更改字体颜色

转载 作者:行者123 更新时间:2023-11-28 22:48:38 27 4
gpt4 key购买 nike

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

最佳答案

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

当它被按下时,它不在 UIControlState NormalUIControlState Highlighted 中。

关于ios - UIButton 自定义按钮不会在选择时更改字体颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12537955/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com