【发布时间】:2017-10-17 14:02:21
【问题描述】:
我正在使用MDCTextInputControllerFilled 并设置activeColor 属性会更改下划线和浮动占位符。但是,我找不到设置闪烁光标颜色的方法,默认情况下它是蓝色的。
有没有办法改变颜色?
【问题讨论】:
我正在使用MDCTextInputControllerFilled 并设置activeColor 属性会更改下划线和浮动占位符。但是,我找不到设置闪烁光标颜色的方法,默认情况下它是蓝色的。
有没有办法改变颜色?
【问题讨论】:
我遇到了同样的问题,并通过子类化 MDCTextField 并覆盖 layoutSubviews 以仅在布局视图后更改 tintColor 来解决它。这对我有用。
例如:
AppaceaTextField.h
#import "MaterialTextFields.h"
@interface AppaceaTextField : MDCTextField
@end
AppaceaTextField.m
#import "AppaceaTextField.h"
@implementation AppaceaTextField
- (void) layoutSubviews{
[super layoutSubviews];
self.tintColor = [UIColor redColor];
}
@end
希望有帮助!
【讨论】:
【讨论】:
由于MDCTextField 是UITextField 的子类,您应该更改tintColor 属性以更改光标的颜色:
mdcTextField.tintColor = .red
【讨论】:
MDCTextField 一定有什么特别之处。 mdcTextField.tintColor = .red 无效。
试试这个
override func viewDidLoad() {
super.viewDidLoad()
textfield.tintColor = .red
}
【讨论】:
MDCTextField 中必须有一些覆盖。
尝试了其他所有方法。除了这个没有任何作用:
let colorScheme = MDCSemanticColorScheme()
colorScheme.primaryColor = .systemBlue // <-- This works in my case
colorScheme.errorColor = .systemRed
let container = MDCContainerScheme()
container.colorScheme = colorScheme
let textField = MDCTextField()
let controller = MDCTextInputControllerUnderline(textInput: textField)
controller.applyTheme(withScheme: scheme)
对于上下文:
pod 'MaterialComponents/TextFields', '~> 104.0.1'
pod 'MaterialComponents/TextFields+Theming', '~> 104.0.1'
【讨论】: