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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:16:43+00:00 2026-06-12T23:16:43+00:00

I’ve got a UITextView, with scrollable text. I’m trying to apply a gradient layer

  • 0

I’ve got a UITextView, with scrollable text.
I’m trying to apply a gradient layer to it, so the bottom of the visible text is always slightly faded out.

Here’s my code:

CAGradientLayer *maskLayer = [CAGradientLayer layer];

maskLayer.colors = [NSArray arrayWithObjects:(id)[[UIColor clearColor] CGColor], (id)[[UIColor yellowColor] CGColor], nil];
maskLayer.locations = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0],
                       [NSNumber numberWithFloat:0.2],
                       [NSNumber numberWithFloat:0.8],
                       [NSNumber numberWithFloat:1.0], nil];
maskLayer.bounds = clueTextView.bounds;
myUITextView.layer.mask = maskLayer;

Right now, this is causing the UITextViewLayer to be completely transparant – I see the background color of the UIView that the UITextViewLayer is as subview of. I can’t see any of the text contained within, although I can select and copy the text to paste in to the notes program.

Any ideas what I’m missing?

  • 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-12T23:16:44+00:00Added an answer on June 12, 2026 at 11:16 pm

    You have several problems.

    The gradient layer’s colors property needs to have the same count as its locations property. You are providing 4 locations but only 2 colors.

    You are setting the gradient layer’s bounds based on clueTextView but you are setting it as the mask of myUITextView.

    You are setting the bounds of the gradient layer, but not its position. The default position is 0,0, meaning that the center of the gradient layer is at the upper-left corner of myUITextView. It is simpler to just set the frame of the gradient layer to the bounds of the text view.

    If you fix all of these problems, you might get the effect you’re looking for.

    - (void)initTextViewMask {
        CAGradientLayer *maskLayer = [CAGradientLayer layer];
        maskLayer.colors = @[
            (id)[UIColor whiteColor].CGColor,
            (id)[UIColor whiteColor].CGColor,
            (id)[UIColor clearColor].CGColor];
        maskLayer.locations = @[ @0.0f, @0.8f, @1.0f ];
        maskLayer.frame = textView_.bounds;
        textView_.layer.mask = maskLayer;
    }
    

    However, you may discover new problems.

    If the user can scroll the text view, you will discover that the gradient moves with the text view, which is probably not what you want. The easiest way to fix this is to embed the text view inside a container UIView, and set the mask on the container view.

    If the text view can change size (perhaps due to device rotation), the mask will not automatically change size with it. You need to update the mask’s frame, in layoutSubviews or viewDidLayoutSubviews.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I know there's a lot of other questions out there that deal with this

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.