iOS: String Drawing
iOS: String Drawing
- Subject: iOS: String Drawing
- From: Development <email@hidden>
- Date: Mon, 11 Jul 2011 23:49:22 -0700
Among the myriad of problems I'm having with this application a new one developed when I began adding a shadow to text.
The default text shadows look terrible on iPhone. This I subclassed UILabel and did an override of drawTextInRect
Well in order to draw with the correct colors I have had to do all my custom stuff and then call [super drawTextInRect:rect];
It all works until an Italic font is used. Then the last maybe 5 pixel are cut out of the text. I've attempted to adjust both the bounding box of the parent view and the subclassed label both, and it does not seem to change the views at all. So I'm not entirely sure how but I'm screwing up adjusting a rectangle… (Hoiw hard is it to add 6 pixels to width of a darn rect?)
Anyway. So I attempted to use a string drawing method, which would among other things allow me to set the alignment. This works, until I click the text (which selects it) And it also fails to draw in the correct color. (Always black instead of whatever it should be)
Is string drawing possible if I want color? I need to override to get nice shadows but it creates this nightmare.
CGSize myShadowOffset = self.offset;
float myColorValues[] = {0, 0, 0, self.depth};
CGContextRef myContext = UIGraphicsGetCurrentContext();
CGContextSaveGState(myContext);
CGColorSpaceRef myColorSpace = CGColorSpaceCreateDeviceRGB();
CGColorRef myColor = CGColorCreate(myColorSpace, myColorValues);
CGContextSetShadowWithColor (myContext, myShadowOffset, self.spread, myColor);
CGSize newSize = rect.size;
CGSize imgSize = [self.text sizeWithFont:self.font];
imgSize.width +=6; //this does nothing
//everything below adjusts for the shadow which is a flipping train wreck of its own.
CGPoint p;
CGFloat x=0.0,y=spread;
if (myShadowOffset.width <=0) {
x =((newSize.width - (imgSize.width+(spread*2)))/2)+abs(myShadowOffset.width);
}
else if(myShadowOffset.width >0){
x =0;
}
p = CGPointMake(x, y);
rect.origin = p;
rect.size = imgSize;
[super drawTextInRect:rect];
CGColorRelease(myColor);
CGColorSpaceRelease(myColorSpace);
CGContextRestoreGState(myContext);
_______________________________________________
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