Why I have to set position at the middle?
Why I have to set position at the middle?
- Subject: Why I have to set position at the middle?
- From: Agha Khan <email@hidden>
- Date: Thu, 02 Jul 2009 11:20:58 -0700
Hi
I am new to Apple programming.
I have UIView and it has CALayer (numberLayer). I would like to write
something at the middle of that layer.
So in my
- (id)initWithFrame:(CGRect)frame function I write somthing like this.
CGRect viewRect = [self bounds];
CGPoint center = CGPointMake(viewRect.size.width / 2.0,
viewRect.size.height / 2.0);
numberLayer = [[NumberLayer alloc] init];
numberLayer.position = center; // I think it should be
CGPointMake(0,0);
numberLayer.bounds = viewRect;
[self.layer addSublayer: numberLayer];
Well for so good.
In my layer
-(void) drawInContext:(CGContextRef)ctx
{
CGRect rect = [self bounds];
CGContextSaveGState(ctx);
CGContextTranslateCTM(ctx, 0.0, rect.size.height);
CGContextScaleCTM(ctx,1.0, -1.0);
CGContextClearRect(ctx, rect);
CGPoint center = CGPointMake(rect.size.width / 2.0,
rect.size.height / 2.0);
// CGPoint center = CGPointMake(0,0.0);
CGContextSelectFont(ctx, "Times New Roman", 16, kCGEncodingMacRoman);
CGContextShowTextAtPoint(ctx, center.x, center.y, "Hello",
strlen("Hello"));
CGContextRestoreGState(ctx);
}
The text is at right position.
It works fine, but why I have to set position at the middle?
Best regards
-Agha
_______________________________________________
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