Welcome to MacBoardz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

rotating an NSString

 
   Macintosh computer (Home) -> Programmer Help RSS
Next:  Problem with Abstract Tree Apple Sample code  
Author Message
Seward S.

External


Since: Jan 24, 2008
Posts: 2



(Msg. 1) Posted: Thu Jan 24, 2008 6:32 am
Post subject: rotating an NSString
Archived from groups: comp>sys>mac>programmer>help (more info?)

I am interested in rotating an NSString 90 degrees, in order to
display a label on a graph's vertical axis. I'm sure there is an easy
way to do this in Cocoa, but have not been able to figure it out. Can
someone point me in the right direction? Thanks.

 >> Stay informed about: rotating an NSString 
Back to top
Login to vote
Seward S.

External


Since: Jan 24, 2008
Posts: 2



(Msg. 2) Posted: Thu Jan 24, 2008 2:36 pm
Post subject: Re: rotating an NSString [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thanks for both of your replies. You helped me a lot!

Steve

 >> Stay informed about: rotating an NSString 
Back to top
Login to vote
David Phillip Oste

External


Since: Apr 25, 2004
Posts: 974



(Msg. 3) Posted: Thu Jan 24, 2008 2:50 pm
Post subject: Re: rotating an NSString [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article
,
"Seward S." wrote:

> I am interested in rotating an NSString 90 degrees, in order to
> display a label on a graph's vertical axis. I'm sure there is an easy
> way to do this in Cocoa, but have not been able to figure it out. Can
> someone point me in the right direction? Thanks.

#import <Cocoa/Cocoa.h>

@interface RotatedView : NSView
{
}
@end

@implementation RotatedView

- (id)initWithFrame:(NSRect)frameRect {
if ((self = [super initWithFrame:frameRect]) != nil) {
// Add initialization code here
}
return self;
}

// example of drawing text at an angle.
- (void)drawRect:(NSRect)rect {
NSAffineTransform *t = [NSAffineTransform transform];
[t translateXBy:200. yBy:200.];
[t rotateByDegrees:40.]; // <-- or 90.
[t translateXBy:-200. yBy:-200.];
[t set];
[@"Hello World" drawAtPoint:NSMakePoint(100., 100.)
withAttributes:nil];
[[NSAffineTransform transform] set];
}

@end
 >> Stay informed about: rotating an NSString 
Back to top
Login to vote
glenn andreas

External


Since: Oct 29, 2007
Posts: 4



(Msg. 4) Posted: Thu Jan 24, 2008 2:50 pm
Post subject: Re: rotating an NSString [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article ,
David Phillip Oster wrote:

> In article
> ,
> "Seward S." wrote:
>
> > I am interested in rotating an NSString 90 degrees, in order to
> > display a label on a graph's vertical axis. I'm sure there is an easy
> > way to do this in Cocoa, but have not been able to figure it out. Can
> > someone point me in the right direction? Thanks.
>
> #import <Cocoa/Cocoa.h>
>
> @interface RotatedView : NSView
> {
> }
> @end
>
> @implementation RotatedView
>
> - (id)initWithFrame:(NSRect)frameRect {
> if ((self = [super initWithFrame:frameRect]) != nil) {
> // Add initialization code here
> }
> return self;
> }
>
> // example of drawing text at an angle.
> - (void)drawRect:(NSRect)rect {
> NSAffineTransform *t = [NSAffineTransform transform];
> [t translateXBy:200. yBy:200.];
> [t rotateByDegrees:40.]; // <-- or 90.
> [t translateXBy:-200. yBy:-200.];
> [t set];

Doing a "set" of the transform is potentially dangerous (since if the
superview has some special transform, you'll loose it). From the
documentation:

You should use this method sparingly because it removes the existing
transformation matrix, which is an accumulation of transformation
matrices for the screen, window, and any superviews. Instead use the
concat method to add this transformation matrix to the current
transformation matrix.


Instead:

[NSGraphicsContext saveGraphicsState];
[t concat];

> [@"Hello World" drawAtPoint:NSMakePoint(100., 100.)
> withAttributes:nil];
> [[NSAffineTransform transform] set];

[NSGraphicsContext restoreGraphicsState];

> }
>
> @end
 >> Stay informed about: rotating an NSString 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Help: Can someone tell me the right way to use an NSString? - Can someone tell me if this is the wrong way to use a NSString? Let's say I want to draw 3 lines. Is this the wrong way to do it? NSString *name; name = @"Line 1"; point.origin.x += point.size.width; [name drawInRect:point withAttributes:at...

Bug with NSString (_CFStringAppendFormatAndArgumentsAux)? - Exception: EXC_BAD_ACCESS (0x0001) Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x00000020 Thread 4 Crashed: 0 com.apple.CoreFoundation 0x9019ea38 _CFStringAppendFormatAndArgumentsAux + 0xd30 1 com.apple.CoreFoundation 0x901a4a4c..

Subclassing NSString - Hello. I want to subclass NSString but it is not working. I am doing this to make [NSString-cString] faster by storing cstring pointer in initWithCString when encoding conversion is not required. This is not working because NSString+alloc returns..

NSString -> c string warning - The following: char *textString; textString = [@"abcdefghijklmnopqrstuvwxyz" cString]; gives me an "assignment discards qualifiers from pointer target type" warning. It works the way it's supposed to, but I *am* getting a warning....

NSString in NSDateFormat'ed cell - Hi, can anyone suggest a quick way to show an NSString in an NSTableView cell that has been formatted as an NSDateFormat ? It's a dynamic special case scenario -- i.e., after a button press, it's possible that there will be a date upon reloading data. ....
   Macintosh computer (Home) -> Programmer Help All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]