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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:19:45+00:00 2026-05-29T05:19:45+00:00

While drawing rectangles in a UIView for ios I keep having the same issue:

  • 0

While drawing rectangles in a UIView for ios I keep having the same issue: the rectangle margins blend their color with the background. I tried several rectangle drawing methods with the same results — using a bezier path, drawing line by line, drawing the margins and filling up the insides of the rectangle.

The view’s frame’s themselves are always correctly draw. I’ve even considered using views whenever I need a rectangle, but that doesn’t seem like the correct way to do things specially because I need to draw many of them.

Here is an example of my problem. For comparison, I’m drawing a rectangular green view with the same dimensions:

CGRect horizontalBar = CGRectMake(2, 2, 10, 6);

UIView* horizontalBarSubView = [[UIView alloc] initWithFrame:horizontalBar];
horizontalBarSubView.backgroundColor = [UIColor greenColor];
[self addSubview:horizontalBarSubView];
[horizontalBarSubView release];

And for the rectangle itself:

CGRect horizontalBar = CGRectMake(2, 20, 10, 6);

UIBezierPath* horizontalBarPath = [UIBezierPath bezierPathWithRect:horizontalBar];
[[UIColor greenColor] set];
[horizontalBarPath fill];

This wields the following result (10x zoom):

10x zoom rectangle test

What is causing the colors to blend?

How can I avoid this?

  • 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-29T05:19:46+00:00Added an answer on May 29, 2026 at 5:19 am

    @Almo is correct that your problem is antialiasing, but are you sure this is the actual code and values? This shouldn’t anti-alias, and my tests show it doesn’t. To get your result, I have to change your path to this:

    CGRect horizontalBar = CGRectMake(2.5, 20.5, 10, 6);
    

    Filling to a path on a fractional pixel will give you the effect you’re seeing. Also, stroking a path on integral pixels with an odd width will anti-alias this way. (All on a non-Retina display; Retina is slightly different.)

    I do not generally recommend turning off anti-aliasing as @Almo suggests. Instead, you just need to make sure your paths draw or fill whole pixels.

    This is covered in more detail in Chapter 6 of iOS 5 Programming Pushing the Limits, page 114.

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

Sidebar

Related Questions

I'm experiencing an issue with GDI+ while custom painting dashed rectangles. The vertical portion
While running my application (which does a good bit of custom drawing) I get
I'm having problems resizing a TPaintBox and drawing on it: On my Form (named
In my program the source rectangle for drawing can either be a regular rectangle,
I'm drawing a rectangle on a custom subclass of NSView which can then be
I'm drawing a whole bunch of Polygons onto a canvas, most of which share
While the C# spec does include a pre-processor and basic directives (#define, #if, etc),
While going through university and from following the development of SO, I've heard a
While I've seen rare cases where private inheritance was needed, I've never encountered a
While setting up CruiseControl, I added a buildpublisher block to the publisher tasks: <buildpublisher>

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.