作者热门文章
- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我正在尝试使用自定义的浅灰色 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/
有没有一种方法可以“标记”对象的属性,使它们在反射中“突出”? 例如: class A { int aa, b; string s1, s2; public int AA
我是一名优秀的程序员,十分优秀!