ios 如何更改 React Native 光标颜色?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33094796/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 07:58:25  来源:igfitidea点击:

How to change React Native cursor color?

iosreact-native

提问by Yi Wang

I am using React Native and I would like to change the cursor color of a text input. I actually got the default blue color.

我正在使用 React Native,我想更改文本输入的光标颜色。我实际上得到了默认的蓝色。

How can I set a global color either in JavaScript or in AppDelegate ?

如何在 JavaScript 或 AppDelegate 中设置全局颜色?

采纳答案by KChen

Yes, we can do it by setting tint color.

是的,我们可以通过设置色调颜色来实现。

In AppDelegate.mof project.

AppDelegate.m项目中。

Adding the below code between self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];and [self.window makeKeyAndVisible];, you can change the global tint color.

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];和之间添加以下代码[self.window makeKeyAndVisible];,您可以更改全局色调颜色。

self.window.tintColor = [UIColor redColor]; // Here is your color.

Or, adding the below code after [self.window makeKeyAndVisible];, you can change the tint color of TextInput/UITextField.

或者,在 之后添加以下代码[self.window makeKeyAndVisible];,您可以更改 TextInput/UITextField 的色调颜色。

[[UITextField appearance] setTintColor:[UIColor redColor]];

Nothing happens when you change the UITextView's tint color.

当您更改 UITextView 的色调颜色时,没有任何反应。

And I couldn't find a way to implement it with a style of JaveScript.

而且我找不到一种使用 JaveScript 样式来实现它的方法。

回答by Thomas Chafiol

There is actually a prop doing this for TextInput : selectionColor

实际上有一个道具为 TextInput 做这个:selectionColor

<TextInput
  selectionColor={'green'}
/>

Here is the documentation.

这是文档

回答by Jo?o Aguiar

Best way to accomplish this, if you want consistence trough the app is putting the bellow code in your root file (index.js)

实现此目的的最佳方法,如果您希望通过应用程序保持一致性,则将波纹管代码放在您的根文件 (index.js) 中

import { TextInput } from 'react-native'
TextInput.defaultProps.selectionColor = 'white'

/*class....*/