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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:59:58+00:00 2026-06-04T22:59:58+00:00

I have a view, which has a CALayer. When I create a CAGradientLayer and

  • 0

I have a view, which has a CALayer. When I create a CAGradientLayer and apply it as the mask of that view’s CALayer, nothing happens. Why?

In -initWithFrame: of the view I do this:

CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor blackColor] CGColor], (id)[[UIColor whiteColor] CGColor], nil];
//[self.layer insertSublayer:gradient atIndex:0];
self.layer.mask = gradient;

If I replace

self.layer.mask = gradient;

with

[self.layer insertSublayer:gradient atIndex:0];

then I see the gradient. It’s from black to white.

What’s the trick?

  • 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-04T22:59:59+00:00Added an answer on June 4, 2026 at 10:59 pm

    The mask property on CALayer uses the alpha component of the mask layer to determine what should be visible and not. Since both of your colors (black and white) are fully opaque (no transparency) the mask has no effect. To fix this you should change one of the colors to a clear color:

    gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor blackColor] CGColor], 
                                                (id)[[UIColor clearColor] CGColor], nil];
    

    That’s the “trick” 😀

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

Sidebar

Related Questions

I have an MVC3 Razor view which has a link that requires user login
not sure how to word this correctly.. so i have a view which has
I have a view based application which has some textboxes that I'm trying to
I have a view which has two labels. When I swipe left I fill
I have a custom view which has a piano keyboard drawn inside of it.
I have a tab view which has a listview in one of these tabs.
I have a list view item which has a button and displays properties on
I have an view in my App which has a number of buttons based
I have a DatePicker working on a View which also has a ViewModel associated
I have an iPhone app which has a Table View-based data input screen with

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.