Re: NSTextView alignment confusion
Re: NSTextView alignment confusion
- Subject: Re: NSTextView alignment confusion
- From: Ron Medina Ballesteros <email@hidden>
- Date: Fri, 16 Apr 2004 22:39:36 -0700
As suggested, I created two NSTextTabs that I added in the
NSMutableParagraphStyle. I then set it as the NSTextView's default
paragraph style.
I'm able to get the text I want to show with the code below to display
the same way as AddressBook's alignment. However I'm a bit concerned if
this was the right approach of simply appending my attributedstrings
together and appending a newline '\n' to separate the data into
several lines then using setAttributedString with NSTextStrorage.
I have a feeling that there is something for much more simpler. Is
there something I'm missing?
Unfortunately I don't have the financial resource to buy the ADC-TV
membership to get access to Session 424 which was said to cover
this particular case. I'll just chalk this one up to a learning
experience through trial and error.
~rb
NSMutableAttributedString *myLabel = [[NSMutableAttributedString
alloc] initWithString: @"\tevaluation code :" attributes:
textAttributes];
NSMutableAttributedString *myInfo = [[NSMutableAttributedString alloc]
initWithString: @"\tEC12345" attributes: textAttributes];
[myLabel appendAttributedString: myInfo];
[myLabel appendAttributedString: [[NSAttributedString alloc]
initWithString: @"\n"]];
NSMutableAttributedString *myLabel1 = [[NSMutableAttributedString
alloc] initWithString: @"\tevaluation code :" attributes:
textAttributes];
NSMutableAttributedString *myInfo1 = [[NSMutableAttributedString
alloc] initWithString: @"\tEC12345" attributes: textAttributes];
[myLabel1 appendAttributedString: myInfo1];
[myLabel appendAttributedString: myLabel1];
//set the paragraph attributes
NSMutableParagraphStyle *dataParaStyle = [[NSMutableParagraphStyle
alloc] init];
//clear all paragraph styles
[dataParaStyle setTabStops:[NSArray array]];
//create and add the 2 tabs stops to where the data will be aligned
with
NSTextTab *tabStopRight = [[NSTextTab alloc] initWithType:
NSRightTabStopType location: 144];
NSTextTab *tabStopLeft = [[NSTextTab alloc] initWithType:
NSLeftTabStopType location: 155];
[dataParaStyle addTabStop: tabStopRight];
[dataParaStyle addTabStop: tabStopLeft];
[tabStopRight release];
[tabStopLeft release];
//we set the paragraph style to the textView
[textView setDefaultParagraphStyle: dataParaStyle];
[[textView textStorage] setAttributedString: myLabel];
On Apr 16, 2004, at 8:06 AM, Fritz Anderson wrote:
The alignment is done with tabs, a right-align tab for the labels and
a left-align tab for the information.
If you have access, look in the ADC members' website for the Session
424 demo applications. The RaisedEditor demo does what you want (as
well as a _lot_ more).
-- F
On 15 Apr 2004, at 7:00 PM, Ron Medina Ballesteros wrote:
I'm trying to create the same lay out in Address Book's NSTextView of
the contact's information where the labels appear to be right aligned
and the
information is left aligned on some kind of vertical line. Similar to
below:
label 1: Some data
some other label: Another data
I can't seem to get over the hump as to how this is done.
I tried using drawAtPoint: and having the label and information
in one string and using a NSParagraphStyle alignment of
NSCenterTextAlignment
but unfortunately this wouldn't allow me to perform the operations of
selecting or copying the text that is drawn.
--
Fritz Anderson
Consulting Programmer
http://resume.manoverboard.org/
_______________________________________________
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.