更改UITextView的字体颜色 [英] Change font color of UITextView

查看:276
本文介绍了更改UITextView的字体颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITextView,用户可以在其中输入文本。假设用户已经输入了一个值。如何通过点击按钮将已输入的文本和未来输入的文本的字体颜色更改为不同的颜色?

I have a UITextView where the user can input text. Say the user has already inputted a value. How can I change the font color of that already typed text and future typed text to a different one with the click of a button?

我已经设置了可以改变文本的颜色,但它只有在我选择一种颜色,我开始打字之前。在我开始输入,我试图改变颜色,它不做任何事情。

I already have it set up where I can change the color of the text but it only works if I choose a color BEFORE I start typing. After I start typing and I attempt to change the color, it doesn't do anything.

我有这个:

-(IBAction)changeInkColor:(id)sender
{
    [inkTextField setTextColor:[UIColor greenColor]]; 
    inkTextField.text=@"text";
}

,并且实际上只有在没有文本已经在视图中。

and that actually works and displays "text" in green only if there is no text already in the view. However if I type something in and then hit this button, nothing happens.

推荐答案

我刚刚试过,我没有问题。我设置了一个按钮 [myTextView setTextColor:[UIColor redColor]];

I just tried that and I had no problems. I set up a button that called [myTextView setTextColor:[UIColor redColor]];

黑色文字颜色,我按下按钮,一切都变红了。

After typing a bit with black text color, I pressed the button, and everything turned red. Then I continued typing, all in red.

您是否使用 setTextColor:这样做吗?

这篇关于更改UITextView的字体颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆