0

i am using this code to show some text in UITextview...in ViewDidLoad Method

self.fontSize = 23.0;
  for(NSUInteger idx = 0; idx < [delegatee.allSelectedVerseEnglish count]; idx++) {
        [combined appendFormat:@"  %d %@", 
         idx + 1, 
         [delegatee.allSelectedVerseEnglish objectAtIndex:idx]];

    };

    maintextview.text =combined;
    maintextview.textColor= [UIColor colorWithRed:0.376f green:0.282f blue:0.173f alpha:1.0f];

    maintextview.font = [UIFont fontWithName:@"Georgia" size:self.fontSize];

combined has the text which includes numeric charter also,how can i identify the numeric character and put brown color and change font to Georgia-Bold only of numercharacters.is it possible by using NSSanner or NSregular expression or something like that?. how to do this? Thanks in advance.

stackiphone
  • 1,245
  • 3
  • 19
  • 41

2 Answers2

1

You cannot do this on a regular text view. It does not allow formatting (although this is a greatly desired feature by many developers). What you need to do is use Core Text and NSAttributedString with a custom view. However, this is very difficult if you need to use selection, or have it be editable.

borrrden
  • 33,256
  • 8
  • 74
  • 109
  • http://stackoverflow.com/questions/1320295/iphone-how-to-check-that-a-string-is-numeric-only is this help for for me? – stackiphone May 22 '12 at 07:56
  • That will only work with the *entire* content of the text view. – borrrden May 22 '12 at 08:14
  • } NSNumberFormatter * f = [[NSNumberFormatter alloc] init]; NSNumber * n = [f numberFromString:combined]; NSLog(@"N: %@", n); i put this code but i get null value – stackiphone May 22 '12 at 08:14
  • I think I misunderstood your question...you mean you want to check if the entire string is numeric? – borrrden May 22 '12 at 08:15
  • so there is no way to separate numeric from string in a text? – stackiphone May 22 '12 at 08:15
  • ,no i just want to get the numeric from my text ,and put a condition to textview if its numeric i want textview.textcolor = [uicolor red color]; if it i string (not numeric) i want the textolor to be green – stackiphone May 22 '12 at 08:17
  • So you mean red and green text in the same UITextView at the same time? That is not possible. – borrrden May 22 '12 at 08:18
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/11557/discussion-between-stackiphone-and-borrrden) – stackiphone May 22 '12 at 08:19
0

alternate option is to make an HTML page and put web View instead of the TextView.

it saves your time.

Prabhat Kasera
  • 1,129
  • 11
  • 28