Centering text vertically within a view
Centering text vertically within a view
- Subject: Centering text vertically within a view
- From: Scot Gellock <email@hidden>
- Date: Wed, 22 Jan 2003 08:34:14 -0800
I have a view in which I need to display text centered both vertically and
horizontally. I have a subclass of NSView (for other reasons) and therefore
have implemented a drawRect method.
The horizontal centering was easy, I created an attributed string with a
paragraph style alignment of NSCenterTextAlignment. And then in my view's
drawRect method, I just send my attributed string a drawInRect message.
In working through how to do the vertical centering I originally thought
that just adjusting the rect used for the drawInRect message would be
enough, but sometimes the text I need to display needs to word wrap,
therfore needing to be displayed on multiple lines. The
NSLineBreakByWordWrapping paragraph style gets me the work wrapping I need.
That's great. But in the case of multiple lines of text, its unclear to me
how to get these lines centered vertically within the view.
I've looked at NSTextView, but this seems heavy, as I only need to display
the text. No editing of the text is necessary. Additionally, I'm not sure
this can do what I'm looking for.
Do I have to figure out the word wrapping myself in order to calculate the
proper vertical offset of the rect used for my drawInRect, or is there an
easier way?
Best regards.
Scot
_______________________________________________
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.