Re: NSTextTab Troubles
Re: NSTextTab Troubles
- Subject: Re: NSTextTab Troubles
- From: Jonathan Jackel <email@hidden>
- Date: Sat, 20 Dec 2003 14:25:43 -0500
A couple of suggestions:
1. You don't need to begin and end editing of a text storage when you
are programmatically changing/creating its contents. You only need to
use "editing" methods to simulate or override what the user can do.
2. Combining tabs and centered alignment in the same paragraph style is
a recipe for disaster. Use two different paragraph styles.
3. There is no need to set the resizable properties of the text view
because they are, by default, what you want. That is, a default text
view is vertically resizable and is not horizontally resizable.
Try this (pseudocode, written in Mail):
- (NSView *)printableView
{
NSDictionary *centeredDict, *flushRightDict;
NSAttributedString *centeredString, *flushRightString;
NSTextView *printView = [[[NSTextView alloc]
initWithFrame:NSMakeRect(0, 0, 480, 200)] autorelease];
NSMutableParagraphStyle *centeredStyle = [[NSMutableParagraphStyle
alloc] init];
NSMutableParagraphStyle *flushRightStyle = [[NSMutableParagraphStyle
alloc] init];
[flushRightStyle setAlignment:NSRightTextAlignment];;
[centeredStyle setAlignment:NSCenterTextAlignment];
centeredDict = [NSDictionary dictionaryWithObjectsAndKeys:
[NSFont boldSystemFontOfSize:14], NSFontAttributeName,
centeredStyle, NSParagraphStyleAttributeName, nil];
flushRightDict = [NSDictionary dictionaryWithObjectsAndKeys:
[NSFont boldSystemFontOfSize:14], NSFontAttributeName,
flushRightStyle, NSParagraphStyleAttributeName, nil];
flushRightString = [[[NSAttributedString alloc]
initWithString:@"TITLE\n" attributes: flushRightDict];
centeredString = [[[NSAttributedString alloc]
initWithString:@"NEWLINE" attributes: centeredDict];
[[printView textStorage] setAttributedString:flushRightString];
[[printView textStorage] appendAttributedString:centeredString];
[printView sizeToFit];
return printView;
}
On Dec 19, 2003, at 11:30 PM, John Devor wrote:
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.
_______________________________________________
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.