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 8006653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:35:05+00:00 2026-06-04T17:35:05+00:00

I am trying to code a routine that would allow me to create a

  • 0

I am trying to code a routine that would allow me to create a UIImage that is a rectangle filled with stripes on a gradient background.

My code is below and works fine for most of the cases I tried it out. Interestingly, and this is the hook, it doesn’t work when I pass it 21 as height and 5 as stripedWidth.

Once I do this, the stripes appear as they should… horizontally.. but vertically they start at like (y=) -40 and end at about (y=) 4 or so. To see this better, each this image showing the effect in question:

Has anyone any idea why this is happening, or even better, what I can do against it?

enter image description here

-(UIImage*) stripedTextureWithStartingColor:(UIColor*) startColor withEndingColor:(UIColor*) endColor withHeight:(NSUInteger) height withStripeWidth:(NSUInteger) stripeWidth withStripeColor:(UIColor*) stripedColor {
  CGSize size = CGSizeMake(2 * stripeWidth, height);
  UIGraphicsBeginImageContext(size);
  CGContextRef context = UIGraphicsGetCurrentContext();
  CGContextSaveGState(context);
  @try {
    CGContextSetAllowsAntialiasing(context, true);
    CGContextSetShouldAntialias(context, true);
    NSArray* colors = [NSArray arrayWithObjects:(id) startColor.CGColor, (id) endColor.CGColor, nil];
    CGFloat locations[2];
    locations[0] = 0.0;
    locations[1] = 1.0;
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef) colors, locations);
    CGColorSpaceRelease(colorSpace);
    CGContextDrawLinearGradient(context, gradient, CGPointZero, CGPointMake(0, size.height - 1), 0);
    CGGradientRelease(gradient);
    CGContextFillPath(context);

    int lineWidth = (int) stripeWidth;
    CGContextSetLineWidth(context, lineWidth / 2);
    int lineCount = (float) size.height / (float) lineWidth;
    lineCount -= 2;

    for (int i=0; i<lineCount; i++) {
      CGContextSetStrokeColorWithColor(context, stripedColor.CGColor);
      float x1 = -size.height + i * 2 * lineWidth - lineWidth;
      float y1 = size.height - 1 + lineWidth;
      float x2 = -size.height + i * 2 * lineWidth + size.height - lineWidth;
      float y2 = -lineWidth;
      CGContextMoveToPoint(context, x1, y1);
      CGContextAddLineToPoint(context, x2, y2);
      CGContextStrokePath(context);
    }

    UIColor* lineTopColor = [[UIColor whiteColor] colorWithAlphaComponent:0.9];
    UIColor* lineBottomColor = [[UIColor darkGrayColor] colorWithAlphaComponent:0.5];

    CGContextSetStrokeColorWithColor(context, lineTopColor.CGColor);
    CGContextMoveToPoint(context, 0, 0);
    CGContextAddLineToPoint(context, size.width + 1, 0);
    CGContextStrokePath(context);

    CGContextSetStrokeColorWithColor(context, lineBottomColor.CGColor);
    CGContextMoveToPoint(context, 0, size.height - 1);
    CGContextAddLineToPoint(context, size.width + 1, size.height - 1);
    CGContextStrokePath(context);

  }
  @finally {
    CGContextRestoreGState(context);
  }
  UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();
  return image; 
}
  • 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-04T17:35:07+00:00Added an answer on June 4, 2026 at 5:35 pm

    Found it, my algorithm was slightly incorrect with the starting of the lines

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a routine that takes a UIImage and returns a
I'm trying to create a routine in my asp.net's main page that will see
I'm trying to create a routing prefix that would be default. http://localhost/heb/mycont would leave
I'm trying write a routine in SQL Server that, when run, would traverse specified
I am trying to code a sort routine against a dynamicaly populated gridview names
I'm trying to code what I think is a fairly routine AJAX pattern using
Is there code that will allow me to read the version of office installed
I'm trying to use personal URLs through the code of my application that function
Briefly, I am trying to write a routine that reads comma separated values from
I am having an issue converting type. I was trying code like this (minimal,

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.