Sorry guys, another question
I have this code here:
The parts in bold is what I am confused on. Neither "sizeWithFont" or "drawInRect" are a methods of NSString so how am I able to call these on an NSString object?
Both are methods of type CGSize, and I found they are defined in the UIStringDrawing.h file that is part of the UIKit but I can't understand the link between them or how I am able to call these methods on NSString objects.
Is there some kind of exception where because this code is all within an overridden drawRect function of a UIView subclass I can call these methods on strings?
I've been digging around the documentation for awhile and haven't found an answer yet :/
I have this code here:
Code:
//Add some text
NSString *text = @"You are getting sleepy.";
//Get a font to draw it in
UIFont *font = [UIFont boldSystemFontOfSize:28];
//Where am I going to draw it?
CGRect textRect;
[B]textRect.size = [text sizeWithFont:font]; //Confusion here[/B]
textRect.origin.x = center.x - textRect.size.width * 0.5;
textRect.origin.y = center.y - textRect.size.height * 0.5;
//Set the fill color of the current context to black
[[UIColor blackColor] setFill];
//Set the shadow to be offset 4 points right, 3 points down
//and dark grey with a blur radius of 2 points
CGSize offset = CGSizeMake(4, 3);
CGColorRef color = [[UIColor darkGrayColor] CGColor];
CGContextSetShadowWithColor(context, offset, 2.0, color);
//Draw the string
[B] [text drawInRect:textRect withFont:font]; //Confusion here[/B]
}
The parts in bold is what I am confused on. Neither "sizeWithFont" or "drawInRect" are a methods of NSString so how am I able to call these on an NSString object?
Both are methods of type CGSize, and I found they are defined in the UIStringDrawing.h file that is part of the UIKit but I can't understand the link between them or how I am able to call these methods on NSString objects.
Is there some kind of exception where because this code is all within an overridden drawRect function of a UIView subclass I can call these methods on strings?
I've been digging around the documentation for awhile and haven't found an answer yet :/