• 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
Finding the active Text View.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Finding the active Text View.


  • Subject: Finding the active Text View.
  • From: Lloyd Thompson <email@hidden>
  • Date: Tue, 5 Oct 2004 17:47:13 -0500

Hey everybody,

I'm developing an app that has multiple NSTextViews and I need to find a way to return the currently active Text View. So, for example, a function that adds a trait to a font, will work between multiple text views and not just in one text field. Here's some code I'm working with - an action that grabs selected text from a textView, puts that into a MutableAttributedString, and applies a new font to that selected area.

- (id)sender
{
NSFont *font;
NSTextStorage *storage = [textView textStorage];
NSMutableAttributedString *attributedString = storage;

[storage beginEditing];
NSRange range = [textView selectedRange];
NSRange fontRange;
unsigned idx = range.location;

while (NSLocationInRange(idx, range)) {
font = [attributedString attribute:NSFontAttributeName atIndex:idx
longestEffectiveRange:&fontRange inRange:range];
fontRange = NSIntersectionRange(fontRange, range);
font = [[NSFontManager sharedFontManager] convertFont:font
toHaveTrait:NSBoldFontMask];
[attributedString addAttribute:NSFontAttributeName value:font range:fontRange];
idx = NSMaxRange(fontRange);
}

[storage endEditing];
}

Thanks!
Lloyd
_______________________________________________
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: TIFFs produced by TIFFRepresentation not portable?
  • Next by Date: Re: Addressbook-like editing?
  • Previous by thread: Re: TIFFs produced by TIFFRepresentation not portable?
  • Next by thread: Saving & Loading Issue
  • Index(es):
    • Date
    • Thread