2016-07-12 5 views
0

私はtext viewが動的にアウトレットを作成している、私はtextviewテキストcolour.iを変更する必要があります動的に選択可能な "本当の"を設定しましたが、テキストは常に黒の色で表示されます理由は分かりません。私はグーグルでどこに到達しましたが、答えを見つけるのは幸運ではありません。私はアウトレットが動的に作成されたテキストビューを持っています、私はテキストビューのテキストを変更する必要がありますcolour.How私はこれを行うことができますか?

+0

です。 – Avi

+0

[UITextViewのフォントの色を変更する]の複製があります。(0120-18753) –

+0

あなたが今まで試みてきたコーディングを私に見せてください。 – user3182143

答えて

0

あなたが動的に作成した各UITextViewのテキストの色を設定してください:

SomeTextView.textColor = [UIColor redColor]; 

ホープこれはあなたを助けます!

0
UITextView *view = [[UITextView alloc]initWithFrame:CGRectMake(50, 100, 100, 100)]; 
view.textColor = [UIColor redColor]; 
view.userInteractionEnabled = YES; 
[self.view addSubview:view]; 
+1

このコードは質問に答えるかもしれませんが、問題の解決方法および/または理由を説明する追加のコンテキストを提供すると、回答の長期的価値が向上します。 – HiDeo

0
UITextView *txtView = [[UITextView alloc]initWithFrame:CGRectMake(10, 100, 100, 100)]; 
txtView.textColor = [UIColor blueColor]; 
[self.view addSubview:txtView]; 

uはTextViewの中で特定の単語の色を表示したい場合はuが最初の4文字の

NSMutableAttributedString *stringText = [[NSMutableAttributedString alloc] initWithString:@"This is awesome"]; 

//緑の色を試すことができます。

[stringText addAttribute: NSForegroundColorAttributeName value: [UIColor greenColor] range: NSMakeRange(0, 4)]; 

//最後の4文字のフォント色を黄色に設定します。

[stringText addAttribute: NSForegroundColorAttributeName value: [UIColor yellowColor] range: NSMakeRange(14, 10)]; 

これはプログラムによって行うことができます。使用するNSMutableAttributedString

NSMutableAttributedString *stringText = [[NSMutableAttributedString alloc] initWithString:@"This is awesome"]; 

//Green color for the first four characters. 
[stringText addAttribute: NSForegroundColorAttributeName value: [UIColor greenColor] range: NSMakeRange(0, 4)]; 

// Sets the font color of last four characters to yellow. 
[stringText addAttribute: NSForegroundColorAttributeName value: [UIColor yellowColor] range: NSMakeRange(14, 10)]; 

このテキストはUITextViewに設定してください。それは動作するはずです。また、テキストが動的に変化する場合は、NSMakeRangeで十分注意してください。 TextViewのテキストの色を変更するための

+0

あなたはまだ問題に直面していますか? – remyr3my

0

最も簡単な方法は、私たちのコードを表示

UITextView *txtviewTextColor = [[UITextView alloc]init]; 
txtviewTextColor.frame = CGRectMake(10, 30, 200, 100); 
txtviewTextColor.scrollEnabled = YES; 
txtviewTextColor.textColor =[UIColor greenColor]; 
txtviewTextColor.userInteractionEnabled = YES; 
[self.view addSubview:txtviewTextColor]; 
関連する問題