Re: How to relayout content of NSTextView so that my tab characters are drawn with width of 4 characters
Re: How to relayout content of NSTextView so that my tab characters are drawn with width of 4 characters
- Subject: Re: How to relayout content of NSTextView so that my tab characters are drawn with width of 4 characters
- From: Lyndsey Ferguson <email@hidden>
- Date: Fri, 19 Feb 2010 13:09:53 -0500
- (void)updateMyTextViewTextAttributes
{
NSMutableParagraphStyle* paragraphStyle = [[myTextView
defaultParagraphStyle] mutableCopy];
if (paragraphStyle == nil) {
paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
}
float charWidth = [[myFont
screenFontWithRenderingMode:NSFontDefaultRenderingMode]
advancementForGlyph:(NSGlyph) ' '].width;
[paragraphStyle setDefaultTabInterval:(charWidth * 4)];
[paragraphStyle setTabStops:[NSArray array]];
[myTextView setDefaultParagraphStyle:paragraphStyle];
NSMutableDictionary* typingAttributes = [[myTextView
typingAttributes] mutableCopy];
[typingAttributes setObject:paragraphStyle
forKey:NSParagraphStyleAttributeName];
[typingAttributes setObject:scriptFont forKey:NSFontAttributeName];
[myTextView setTypingAttributes:typingAttributes];
NSRange rangeOfChange = NSMakeRange(0, [[myTextView string] length]);
[myTextView shouldChangeTextInRange:rangeOfChange replacementString:nil];
[[myTextView textStorage] setAttributes:typingAttributes
range:rangeOfChange];
[myTextView didChangeText];
}
On Fri, Feb 19, 2010 at 12:35 PM, Douglas Davidson <email@hidden> wrote:
>
> On Feb 19, 2010, at 9:03 AM, email@hidden wrote:
>
>> I've tried calling my updateMyTextViewTextAttributes call when myTextView has the new myFont set. That doesn't change a thing.
>
> With updateMyTextViewTextAttributes as described, it will set the paragraph style for new text but won't change the paragraph style for existing text. What you would want to do would be to apply the new paragraph style to the existing text, by setting it as the value for NSParagraphStyleAttributeName on the text storage. To make this work well with the text view, you would probably want to surround this with calls to shouldChange/didChange methods--take a look at some of the samples for code examples of this sort of thing.
>
> Douglas Davidson
>
>
--
Lyndsey Ferguson
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden