Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3220460
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:45:51+00:00 2026-05-17T15:45:51+00:00

is it possible to create such a UILabel with inner and outer shadow? alt

  • 0

is it possible to create such a UILabel with inner and outer shadow?

alt text http://dl.getdropbox.com/u/80699/Bildschirmfoto%202010-07-12%20um%2021.28.57.png

i only know shadowColor and shadowOffset

zoomed:

alt text http://dl.getdropbox.com/u/80699/Bildschirmfoto%202010-07-12%20um%2021.39.56.png

thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:45:51+00:00Added an answer on May 17, 2026 at 3:45 pm

    The answer by dmaclach is only suitable for shapes that can easily be inverted. My solution is a custom view that works with any shape and also text. It requires iOS 4 and is resolution independent.

    First, a graphical explanation of what the code does. The shape here is a circle.
    alt text

    The code draws text with a white dropshadow. If it’s not required, the code could be refactored further, because the dropshadow needs to be masked differently. If you need it on an older version of iOS, you would have to replace the block and use an (annoying) CGBitmapContext.

    - (UIImage*)blackSquareOfSize:(CGSize)size {
      UIGraphicsBeginImageContextWithOptions(size, NO, 0);  
      [[UIColor blackColor] setFill];
      CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, size.width, size.height));
      UIImage *blackSquare = UIGraphicsGetImageFromCurrentImageContext();
      UIGraphicsEndImageContext();
      return blackSquare;
    }
    
    
    - (CGImageRef)createMaskWithSize:(CGSize)size shape:(void (^)(void))block {
      UIGraphicsBeginImageContextWithOptions(size, NO, 0);  
      block();
      CGImageRef shape = [UIGraphicsGetImageFromCurrentImageContext() CGImage];
      UIGraphicsEndImageContext();  
        CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(shape),
                                          CGImageGetHeight(shape),
                                          CGImageGetBitsPerComponent(shape),
                                          CGImageGetBitsPerPixel(shape),
                                          CGImageGetBytesPerRow(shape),
                                          CGImageGetDataProvider(shape), NULL, false);
      return mask;
    }
    
    
    - (void)drawRect:(CGRect)rect {
      UIFont *font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:40.0f];
      CGSize fontSize = [text_ sizeWithFont:font];
    
      CGImageRef mask = [self createMaskWithSize:rect.size shape:^{
        [[UIColor blackColor] setFill];
        CGContextFillRect(UIGraphicsGetCurrentContext(), rect);
        [[UIColor whiteColor] setFill];
        // custom shape goes here
        [text_ drawAtPoint:CGPointMake((self.bounds.size.width/2)-(fontSize.width/2), 0) withFont:font];
        [text_ drawAtPoint:CGPointMake((self.bounds.size.width/2)-(fontSize.width/2), -1) withFont:font];
      }];
    
      CGImageRef cutoutRef = CGImageCreateWithMask([self blackSquareOfSize:rect.size].CGImage, mask);
      CGImageRelease(mask);
      UIImage *cutout = [UIImage imageWithCGImage:cutoutRef scale:[[UIScreen mainScreen] scale] orientation:UIImageOrientationUp];
      CGImageRelease(cutoutRef);  
    
      CGImageRef shadedMask = [self createMaskWithSize:rect.size shape:^{
        [[UIColor whiteColor] setFill];
        CGContextFillRect(UIGraphicsGetCurrentContext(), rect);
        CGContextSetShadowWithColor(UIGraphicsGetCurrentContext(), CGSizeMake(0, 1), 1.0f, [[UIColor colorWithWhite:0.0 alpha:0.5] CGColor]);
        [cutout drawAtPoint:CGPointZero];
      }];
    
      // create negative image
      UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
      [[UIColor blackColor] setFill];
      // custom shape goes here
      [text_ drawAtPoint:CGPointMake((self.bounds.size.width/2)-(fontSize.width/2), -1) withFont:font];
      UIImage *negative = UIGraphicsGetImageFromCurrentImageContext();
      UIGraphicsEndImageContext(); 
    
      CGImageRef innerShadowRef = CGImageCreateWithMask(negative.CGImage, shadedMask);
      CGImageRelease(shadedMask);
      UIImage *innerShadow = [UIImage imageWithCGImage:innerShadowRef scale:[[UIScreen mainScreen] scale] orientation:UIImageOrientationUp];
      CGImageRelease(innerShadowRef);
    
      // draw actual image
      [[UIColor whiteColor] setFill];
      [text_ drawAtPoint:CGPointMake((self.bounds.size.width/2)-(fontSize.width/2), -0.5) withFont:font];
      [[UIColor colorWithWhite:0.76 alpha:1.0] setFill];
      [text_ drawAtPoint:CGPointMake((self.bounds.size.width/2)-(fontSize.width/2), -1) withFont:font];  
    
      // finally apply shadow
      [innerShadow drawAtPoint:CGPointZero];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

MvcSiteMap - https://github.com/maartenba/MvcSiteMapProvider [originally at: http://mvcsitemap.codeplex.com/] Is it possible to create such links in
Is it possible to create HTML lists such as ordered and unordered lists without
Is it possible to create virtual files (such as /proc/uptime for exanple) in java?
Is it possible to create an object from a dictionary in python in such
Is it possible to create a regular expression that matches a comparison such as
Is it possible to create a driver (windows/mac) for a custom usb hub such
Is it possible and how to create objects of such classes like NSString from
As it is MyClass x = 120; , is it possible to create such
Is is possible in SQL Server 2008 to create such a constraint that would
Is it possible to create a database such that there are 2 tables across

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.