Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Setting Tab Stops (again)



I am trying to set a different collection of tab stops in an NSTextView
besides the default set, which are 28 points apart. I am setting up a fixed
point font, and I want a tab stop every 4 columns (5, 9, 13, etc). My window
is fairly wide, so I am setting up 64 tabs stops. My code looks like:

NSMutableParagraphStyle *paragraphStyle;
float fCharacterWidth, fTabPosition;
long lIndex;
NSMutableArray *tabArray = [NSMutableArray
arrayWithCapacity:64];
NSFont *textFont = [NSFont
userFixedPitchFontOfSize:14.0];

[myTextView setFont:textFont];
fCharacterWidth = [textFont widthOfString:@"X"];
fTabPosition = 5.0 * fCharacterWidth;
[tabArray addObject:[[NSTextTab alloc]
initWithType:NSLeftTabStopType location:fTabPosition]];
for(lIndex=1; lIndex<64; ++lIndex)
{
fTabPosition += 4.0 * fCharacterWidth;
[tabArray addObject:[[NSTextTab alloc]
initWithType:NSLeftTabStopType location:fTabPosition]];
}
paragraphStyle = [[NSParagraphStyle defaultParagraphStyle]
mutableCopy];
[paragraphStyle setTabStops:tabArray];
myTextStorage = [myTextView textStorage];
[myTextStorage
setAttributes:[NSDictionary
dictionaryWithObject:paragraphStyle forKey:NSParagraphStyleAttributeName]
range:NSMakeRange(0,[myTextStorage length])];


I am assuming this fails because to start with, this NSTextView has no
contents, so it is setting the attributes of nothing.

How do I set the default attributes of my NSTextView so that my tab stop
array sticks, even if the contents of the view are deleted and replaced with
some other text contents.

Thanks.

Michael Christian
Thomson multimedia Inc.




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.