Reputation: 176
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?
Upvotes: 0
Views: 976
Reputation: 1064
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'
Upvotes: 0
Reputation: 3149
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.
Upvotes: 1
Reputation: 59
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!
Upvotes: 3
Reputation: 58049
Since MDCTextField
is a subclass of UITextField
, you should change the tintColor
property to change the cursor's color:
mdcTextField.tintColor = .red
Upvotes: 1
Reputation: 115
try this
override func viewDidLoad() {
super.viewDidLoad()
textfield.tintColor = .red
}
Upvotes: 0