I'm using MDCTextInputControllerFilled
and setting the activeColor
property changes the underline and the floating placeholder. However, I cannot find a way to set the blinking cursor color, it's blue by default.
Is there a way of changing the color?
Asked
Active
Viewed 909 times
0

leppen
- 158
- 1
- 6
5 Answers
3
I had the same problem and got around it by subclassing MDCTextField and overriding layoutSubviews to change the tintColor only after the view is laid out. This worked for me.
Ex:
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
Hope that helps!

appacea
- 59
- 1
- 2
1
Since MDCTextField
is a subclass of UITextField
, you should change the tintColor
property to change the cursor's color:
mdcTextField.tintColor = .red

Ahmad F
- 30,560
- 17
- 97
- 143

Tamás Sengel
- 55,884
- 29
- 169
- 223
-
1Thanks, but the cursor color stays the same. There must be something special with `MDCTextField`. `mdcTextField.tintColor = .red` has no effect. – leppen Oct 17 '17 at 15:38
1
Thanks for using MDC-iOS.
Cursor color has just been added as a parameter on MDCTextField (.cursorColor).
It was included in the release 38.1.0.

Will Larche
- 3,119
- 7
- 26
- 34
0
try this
override func viewDidLoad() {
super.viewDidLoad()
textfield.tintColor = .red
}

Carlos Norena
- 115
- 7
-
Yeah, but nothing happens when I do that. There must be some override in `MDCTextField`. – leppen Oct 17 '17 at 15:08
0
Tried everything else. Nothing works except this:
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)
For context:
pod 'MaterialComponents/TextFields', '~> 104.0.1'
pod 'MaterialComponents/TextFields+Theming', '~> 104.0.1'

MkVal
- 1,044
- 1
- 11
- 17