• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Setting alignment of NSTextView programmatically [SOLVED]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Setting alignment of NSTextView programmatically [SOLVED]


  • Subject: Re: Setting alignment of NSTextView programmatically [SOLVED]
  • From: Ken Worley <email@hidden>
  • Date: Fri, 15 Feb 2008 13:35:17 -0700

On Feb 13, 2008, at 3:18 PM, Ken Worley wrote:

Hi all,

I can't seem to grok exactly the right way to align a plain text NSTextView (left, center or right). I modified the ButtonMadness sample project to experiment by replacing the code that creates a code-based segment control with a code-based text view like this that should be right-aligned:

buttonFrame = [placeHolder5 frame];

codeBasedTextView = [[NSTextView alloc] initWithFrame:buttonFrame];
[codeBasedTextView setEditable:NO];
[codeBasedTextView setSelectable:YES];
[codeBasedTextView setDrawsBackground:NO];
[codeBasedTextView setRichText:NO];
[codeBasedTextView setImportsGraphics:NO];
[codeBasedTextView alignRight:nil];
[codeBasedTextView setString:@"a string"];
[segmentBox addSubview:codeBasedTextView];
[placeHolder5 removeFromSuperview]; // we are done with the place holder, remove it from the window


but the string still shows up left aligned rather than right aligned. I'm obviously not doing something right, but I'm a little new to all the Cocoa APIs. Any help would be appreciated. My goal would be that if the NSTextView auto-resizes and becomes wider, the text would automatically follow the right edge.

Documentation for alignRight does say:

"This action method applies right alignment to selected paragraphs (or all text if the receiver is a plain text object)."

and, as nearly as I can tell, the text view is set up to be plain text, but maybe I don't understand that part either.


Here's the solution I've got for now that works in the sample project:

Take out the alignRight message in the above and replace it with this:

	NSParagraphStyle* tStyle = [NSParagraphStyle defaultParagraphStyle];
	NSMutableParagraphStyle* tMutStyle = [tStyle mutableCopy];
	[tMutStyle setAlignment:NSRightTextAlignment];
	[codeBasedTextView setDefaultParagraphStyle:tMutStyle];

Oddly enough, it does not work if I start with [codeBasedTextView defaultParagraphStyle]. Also, I still can't understand why simply calling alignRight doesn't work since it's supposed to apply to all text if the receiver is plain text...

Ken


-- Ken Worley Software Engineer, Tiberius, Inc.



_______________________________________________

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


  • Follow-Ups:
    • Re: Setting alignment of NSTextView programmatically [SOLVED]
      • From: Douglas Davidson <email@hidden>
References: 
 >Setting alignment of NSTextView programmatically (From: Ken Worley <email@hidden>)

  • Prev by Date: Re: Segmented Control Question?
  • Next by Date: Re: [Foo new] vs [[Foo alloc] init]:
  • Previous by thread: Re: Setting alignment of NSTextView programmatically
  • Next by thread: Re: Setting alignment of NSTextView programmatically [SOLVED]
  • Index(es):
    • Date
    • Thread