• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
iOS: String Drawing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: iOS: String Drawing
      • From: David Duncan <email@hidden>
    • Re: iOS: String Drawing
      • From: Graham Cox <email@hidden>
  • Prev by Date: Re: IOS graphics
  • Next by Date: Autosizing mask doesn't work with NSSegmentedControl
  • Previous by thread: Re: Gdata Google calander
  • Next by thread: Re: iOS: String Drawing
  • Index(es):
    • Date
    • Thread