Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can add this method to a UIView category and reuse as needed. It applies a linear black gradient from "theColor" to transparent to the given view.</p> <p>You should have QuartzCore.framework in your project in order to use the CAGradientLayer object.</p> <pre><code>+ (void)addLinearGradientToView:(UIView *)theView withColor:(UIColor *)theColor transparentToOpaque:(BOOL)transparentToOpaque { CAGradientLayer *gradient = [CAGradientLayer layer]; //the gradient layer must be positioned at the origin of the view CGRect gradientFrame = theView.frame; gradientFrame.origin.x = 0; gradientFrame.origin.y = 0; gradient.frame = gradientFrame; //build the colors array for the gradient NSArray *colors = [NSArray arrayWithObjects: (id)[theColor CGColor], (id)[[theColor colorWithAlphaComponent:0.9f] CGColor], (id)[[theColor colorWithAlphaComponent:0.6f] CGColor], (id)[[theColor colorWithAlphaComponent:0.4f] CGColor], (id)[[theColor colorWithAlphaComponent:0.3f] CGColor], (id)[[theColor colorWithAlphaComponent:0.1f] CGColor], (id)[[UIColor clearColor] CGColor], nil]; //reverse the color array if needed if(transparentToOpaque) { colors = [[colors reverseObjectEnumerator] allObjects]; } //apply the colors and the gradient to the view gradient.colors = colors; [theView.layer insertSublayer:gradient atIndex:0]; } </code></pre> <p>Please note that you should have the backgroundColor of theView set to clearColor so that it doesn't interfere with the gradient. Also, for the results shown in the screenshot, the transparentToOpaque flag should be YES. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload