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

  • Home
  • SEARCH
  • 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 7981341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:20:23+00:00 2026-06-04T10:20:23+00:00

iOS 5 changed the way the built-in Google Maps App draws routes: I would

  • 0

iOS 5 changed the way the built-in Google Maps App draws routes:

Apple's line

I would now like to replicate the design of the route overlay in my own app but I am currently only able to draw a plain blue line. I would like to add the 3D-effect with the gradient, borders and the glow. Any ideas on how to accomplish this?

Currently I’m using the following code:

CGContextSetFillColorWithColor(context, fillColor.CGColor);
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context, lineWidth);
CGContextAddPath(context, path);
CGContextReplacePathWithStrokedPath(context);
CGContextFillPath(context);

Resulting in a rather ugly line:

my line

Thanks!

Update: The solution should work on iOS 4.0 and up.

  • 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-06-04T10:20:24+00:00Added an answer on June 4, 2026 at 10:20 am

    I think that @ChrisMiles is correct in that the segments are probably being drawn individually. (I initially thought that this might have been doable using CGPatternRef but you don’t have any access to the CTM or path endpoints inside the pattern drawing callback.)

    With this in mind, here is an exceedingly crude, back-of-the-envelope example of how you might begin such an effort (filling the segments individually). Note that:

    • gradient colors are guessed
    • end caps are nonexistent and will need to be separately implemented
    • some aliasing artifacts remain
    • not a great deal of attention was paid to performance

    Hopefully this can get you started at least (and works through some of the analytic geometry).

    -  (CGGradientRef)lineGradient
    {
        static CGGradientRef gradient = NULL;
        if (gradient == NULL) {
            CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
            CGColorRef white = [[UIColor colorWithWhite:1.f
                                                  alpha:0.7f] CGColor];
            CGColorRef blue = [[UIColor colorWithRed:0.1f
                                               green:0.2f
                                                blue:1.f
                                               alpha:0.7f] CGColor];
            CGColorRef lightBlue = [[UIColor colorWithRed:0.4f
                                                    green:0.6f
                                                     blue:1.f
                                                    alpha:0.7f] CGColor];
            CFMutableArrayRef colors = CFArrayCreateMutable(kCFAllocatorDefault, 
                                                            8,
                                                            NULL);
            CFArrayAppendValue(colors, blue);
            CFArrayAppendValue(colors, blue);
            CFArrayAppendValue(colors, white);
            CFArrayAppendValue(colors, white);
            CFArrayAppendValue(colors, lightBlue);
            CFArrayAppendValue(colors, lightBlue);
            CFArrayAppendValue(colors, blue);
            CFArrayAppendValue(colors, blue);
            CGFloat locations[8] = {0.f, 0.08f, 0.14f, 0.21f, 0.29f, 0.86f, 0.93f, 1.f};
            gradient = CGGradientCreateWithColors(colorSpace,
                                                  colors,
                                                  locations);
            CFRelease(colors);
            CGColorSpaceRelease(colorSpace);
        }
        return gradient;
    }
    
    - (void)drawRect:(CGRect)rect
    {
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSaveGState(context);
    
        CGContextSetAllowsAntialiasing(context, YES);
        CGContextSetShouldAntialias(context, YES);
    
        // Fill background color
        [[UIColor whiteColor] setFill];
        UIRectFill(rect);
    
        // Build a path
        CGFloat strokeWidth = 10.f;
        CGContextSetLineWidth(context, strokeWidth);
    
        CGGradientRef gradient = [self lineGradient];
    
        CGPoint points[9] = {
            CGPointMake(10.f, 25.f),
            CGPointMake(100.f, 100.f),
            CGPointMake(100.f, 150.f),
            CGPointMake(22.f, 300.f),
            CGPointMake(230.f, 400.f),
            CGPointMake(230.f, 200.f),
            CGPointMake(300.f, 200.f),
            CGPointMake(310.f, 160.f),
            CGPointMake(280.f, 100.f)
        };
    
    
        for (NSUInteger i = 1; i < 9; i++) {
            CGPoint start = points[i - 1];
            CGPoint end = points[i];
            CGFloat dy = end.y - start.y;
            CGFloat dx = end.x - start.x;
            CGFloat xOffset, yOffset;
            // Remember that, unlike Cartesian geometry, origin is in *upper* left!
            if (dx == 0) {
                // Vertical to start, gradient is horizontal
                xOffset = 0.5 * strokeWidth;
                yOffset = 0.f;
                if (dy < 0) {
                    xOffset *= -1;
                }
            }
            else if (dy == 0) {
                // Horizontal to start, gradient is vertical
                xOffset = 0.f;
                yOffset = 0.5 * strokeWidth;
            }
            else {
                // Sloped
                CGFloat gradientSlope = - dx / dy;
                xOffset = 0.5 * strokeWidth / sqrt(1 + gradientSlope * gradientSlope);
                yOffset = 0.5 * strokeWidth / sqrt(1 + 1 / (gradientSlope * gradientSlope));
                if (dx < 0 && dy > 0) {
                    yOffset *= -1;
                }
                else if (dx > 0 && dy < 0) {
                    xOffset *= -1;
                }
                else if (dx < 0 && dy < 0) {
                    yOffset *= -1;
                    xOffset *= -1;
                }
                else {
                }
            }
            CGAffineTransform startTransform = CGAffineTransformMakeTranslation(-xOffset, yOffset);
            CGAffineTransform endTransform = CGAffineTransformMakeTranslation(xOffset, -yOffset);
            CGPoint gradientStart = CGPointApplyAffineTransform(start, startTransform);
            CGPoint gradientEnd = CGPointApplyAffineTransform(start, endTransform);
    
            CGContextSaveGState(context);
            CGContextMoveToPoint(context, start.x, start.y);
            CGContextAddLineToPoint(context, end.x, end.y);
            CGContextReplacePathWithStrokedPath(context);
            CGContextClip(context);
            CGContextDrawLinearGradient(context, 
                                        gradient, 
                                        gradientStart, 
                                        gradientEnd, 
                                        kCGGradientDrawsAfterEndLocation | kCGGradientDrawsBeforeStartLocation);
            CGContextRestoreGState(context);
        }
    
        CGContextRestoreGState(context);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have built an iOS app which I would now like to test converting
Does iOS offer a way for an app to query the device for information
If I were to send an email from any ios app (non built in
Is there a way to check iOS to see if another app has been
I have an audio app that is having some problems with the way iOS
I am using generic code (from the iOS Fireworks demo) in a slightly changed
Possible Duplicate: Change icon on of an App in iOS 4 in run-time Is
My iOS app has a need to uniquely identify each device so it can
I am working on an app for iOS 4.0. The app was originally on
Is there a way to change the time the iOS keyboard animation takes?

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.