I'm new to subclassing, but I wanted a UILabel subclass to give any text within the label to have a 3-pixel outline. From this page, I used this method:
- (void)drawTextInRect:(CGRect)rect
{
CGSize shadowOffset = self.shadowOffset;
UIColor *textColor = self.textColor;
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(c, 3);
CGContextSetLineJoin(c, kCGLineJoinRound);
CGContextSetTextDrawingMode(c, kCGTextStroke);
self.textColor = [UIColor whiteColor];
[super drawTextInRect:rect];
CGContextSetTextDrawingMode(c, kCGTextFill);
self.textColor = textColor;
self.shadowOffset = CGSizeMake(0, 0);
[super drawTextInRect:rect]; self.shadowOffset = shadowOffset;
}
This works great, and I can change the colors to display any color I'd like for both the text and the outline.
Can someone let me know how to create a property called "outlineColor" that will allow me to set this subclass to any label I want and change the color of the outline?
Essentially, I'd like to be able to set a label's class to "CustomLabelClass" and then within some other class I'd like to say something like:
[myLabel setOutlineColor:[UIColor whiteColor]];
I'm not sure how to go about this. Thanks.