NSTextTab Troubles
NSTextTab Troubles
- Subject: NSTextTab Troubles
- From: John Devor <email@hidden>
- Date: Fri, 19 Dec 2003 23:30:02 -0500
Hello. I'm trying to print (using an NSTextView) one line separated in
the middle using NSTextTabs. One part should be aligned center while
the other should be aligned right. Here's what I've got so far (though
in this code I'm not dividing the line... just trying to get the
@"TITLE" to be aligned right):
- (NSView *)printableView
{
NSTextView *printView;
NSDictionary *titleAttr;
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle
alloc] init];
[paragraphStyle setAlignment:NSCenterTextAlignment];
//By default, text is centered
// CREATE THE PRINT VIEW
// 480 pixels wide seems like a good width for printing text
printView = [[[NSTextView alloc] initWithFrame:NSMakeRect(0, 0,
480, 200)] autorelease];
[printView setVerticallyResizable:YES];
[printView setHorizontallyResizable:NO];
[[printView textStorage] beginEditing];
/* Title */
titleAttr = [NSDictionary dictionaryWithObject:[NSFont
boldSystemFontOfSize:14] forKey:NSFontAttributeName];
[[printView textStorage]
appendAttributedString:[[[NSAttributedString alloc]
initWithString:@"\tTITLE" attributes:titleAttr] autorelease]];
[[printView textStorage]
appendAttributedString:[[[NSAttributedString alloc]
initWithString:@"\nNEXTLINE" attributes:titleAttr]
autorelease]];
[paragraphStyle addTabStop:[[[NSTextTab alloc]
initWithType:NSRightTabStopType location:0] autorelease]];
// Center the title
[[printView textStorage] addAttribute:NSParagraphStyleAttributeName
value:paragraphStyle range:NSMakeRange(0,[[printView textStorage]
length])];
[[printView textStorage] endEditing];
[printView sizeToFit];
return printView;
}
Anyone?
- John D.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.