gpt4 book ai didi

ios - UIButton 触摸时不显示突出显示

转载 作者:技术小花猫 更新时间:2023-10-29 10:57:06 24 4
gpt4 key购买 nike

我正在尝试使用自定义的浅灰色 UIColor 突出显示我的 UIButton,并使文本变为白色。但是,我不确定该怎么做;这就是我在创建 UIButton 方面取得的进展。

cancelButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
cancelButton.frame = CGRectMake(10.0, calculatorView.frame.size.height-55, 100.0, 45.0);
[cancelButton addTarget:self action:@selector(calculateMethod:)forControlEvents:UIControlEventTouchDown];
[[cancelButton titleLabel] setFont:[UIFont fontWithName: @"Super-text" size:20.0]];
[cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];

最佳答案

要使白色文本突出显示,只需执行以下操作:

[cancelButton setTitleColor:[UIColor whiteColor]
forState:UIControlStateHighlighted];

要更改背景,您需要执行 setBackgroundImage:forState: 并使用具有图案颜色的 UIImage,或者子类化 UIButton 并在 setHighlight: 方法中设置适当的背景颜色。

编辑:Swift 2.x 版本

cancelButton.setTitleColor(.whiteColor(), forState: Highlighted)

编辑:Swift 3.0 版本

cancelButton.setTitleColor(.white, for: .highlighted)

关于ios - UIButton 触摸时不显示突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21133856/

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