• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Regarding Font style in an NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Regarding Font style in an NSTextView


  • Subject: Re: Regarding Font style in an NSTextView
  • From: Matt Neuburg <email@hidden>
  • Date: Fri, 24 Sep 2004 08:04:13 -0700

On Fri, 24 Sep 2004 15:51:00 +0530, Kishore <email@hidden> said:
>I want to change the text (with different styles of letters) in a
>textView to uppercase letters, while i am doing that using the
>uppercaseString method in NSString class, the resulting string comes
>with a single font style.
>I want the font styles of different letters should be preserved and
>should be changed to uppercase string.
>
>So any one let me know how to achieve the result by preserving the Font
>styles.

Something like this, I think:

    NSMutableAttributedString* s = [textview textStorage];
    NSRange r = NSMakeRange(0,1);
    [s beginEditing];
    while (r.location < [s length]) {
        [s attributesAtIndex: r.location
         longestEffectiveRange:&r inRange:NSMakeRange(0,[s length])];
        [s replaceCharactersInRange: r withString: [[[s string]
         substringWithRange: r] uppercaseString]];
        r = NSMakeRange(NSMaxRange(r),1);
    }
    [s endEditing];

This will change the selection, so preserve and restore if desired. m.

--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide
<http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt>



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Loading a view from a nib multiple times
  • Next by Date: Re: Loading a view from a nib multiple times
  • Previous by thread: Regarding Font style in an NSTextView
  • Next by thread: KVO and dealloc
  • Index(es):
    • Date
    • Thread