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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:46:06+00:00 2026-05-28T19:46:06+00:00

I am creating an iOS user interface to allow a user to pick a

  • 0

I am creating an iOS user interface to allow a user to pick a rectangle within an existing image, dragging the corners of that rectangle to the desired size. I now have four custom UIButtons (30% alpha) and a custom view (also with 30% alpha) that draws the dashed lines between the four corner buttons.

To “improve” the interface, I would like my drawRect code to make the cropped portion of the image appear “normal” while everything outside the cropped region is washed out (filled with white color, which will give me the correct effect since the UIView is set to 30% alpha).

The obvious algorithm would be:

  1. Fill the entire image with [UIColor whiteColor] fill
  2. Draw the four dashed lines with a [UIColor clearColor] fill

When I do this, the clear fill isn’t showing up. I believe this is because the “fill” of the clear color in step #2 isn’t being seen because the pixels were already set to white in step #1. Perhaps there’s a blend mode that will allow me to see the transparency of the second rectangle? I’m not sure about the various blend modes.

My second attempt, which works, does the following:

  1. Draw the four dashed lines with [UIColor clearColor] fill
  2. Draw four additional rectangles with [UIColor whiteColor] fill, each representing the portions to the left, right, above, and below the cropped region.

As I mention, this method works, but seems to me there should be a simpler way instead of me having to calculate these four additional rectangles each and every time.

There is a similar question on SO Create layer mask with custom-shaped hole that uses CALayer and masks, but this seems to be overkill for what I need.

Does anybody have any suggestions on how to improve 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-28T19:46:07+00:00Added an answer on May 28, 2026 at 7:46 pm

    You can set the blend mode to kCGBlendModeCopy and use clearColor to reset a pixel’s alpha to zero. You can presumably also use kCGBlendModeClear but I haven’t tested that.

    You can also set the clipping path to just contain the pixels you want cleared and call CGContextClearRect(gc, CGRectInfinite).

    If you want to use a clipping mask with a hole in it, you can do so without using a CALayer, and you can build it a little more simply than in the answer you linked, by using the even-odd rule and CGRectInfinite:

    CGContextSaveGState(GC); {
        CGContextBeginPath(gc);
        CGContextAddRect(gc, myRect); // or whatever simple path you want here
        CGContextAddRect(gc, CGRectInfinite);
        CGContextEOClip(gc);
    
        // drawing code here is clipped to the exterior of myRect
    
    } CGContextRestoreGState(gc);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating an iOS user interface with a lot of different UIImageViews that will
Creating a google map with store locations within 50 miles of user entered address.
I'm in the process of creating a universal iOS app that, amongst other functions,
We're creating a game that will run on iOS, Android and in the web
I am creating an application in iOS SDK and the user must enter a
I am creating an iOS app that reads data from a single SQLITE table
I have a SQLite database that I am creating in my iOS application. A
Goal: Allow a user to authentication with Facebook into an iOS application which requires
I am creating an iOS app without using Interface Builder and I seem to
I’m currently creating an iOS app that uploads files to a server. As multiple

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.