ios - How do I create a UIView subclass with a transparent gradient background? -


I want to create a custom UIView which has a transparent gradient background to make the text more This custom view appears on the rear view.

Here is an example image:

Enter image details here

Paint the orange box under my transparent gradient view is a UIView . Then I will put text at the top of the transparent shield view and because of its darkness, the text will appear more, but you can see some orange box behind it.

I am UIView .

  - (zero) draw in my custom  UIView  's  drawRect  : (CGRTact) shortcut {CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB (); CGContextRef Reference = UIGraphicsGetCurrentContext (); NSArray * gradientColors = @ [[id] [UIColor colorWithWhite: 0.0 alpha: 0.0] .Color, (id) [UIColor colorWithWhite: 0.0 alpha: 0.55] .CGColor, (id) [UIColor colorWithite: 0.0 alpha: 0.7]]; CGFloat Gradient Lesses [] = {0, 0.77, 1}; CGGradientRef Slope = CGGradientCreateWithColors (Color space, (__Bridge CFArrayRef) Gradient Colors, Gradient Lacs); CGPoint StartPoint = CGPEXMAC (CGRactGetMIDX (RECT), CGRactGatmini (RECT)); CGPoint Endpoint = CGPXMake (CGRactGetMIDX (RECT), CGRactGetMXY (Rect)); CGContextDrawLinearGradient (Reference, Slope, Start Page, End Page, 0); CGGradientRelease (Slope); }   

But it does not support transparency, like when I add that code from UIView to self.view Opaque black

How do I do this in CSS:

  Background image: Linear-gradient (-180 degrees, RGBA (0,0,0,0.00.00) 0% , RGBA (0,0,0,0,5,5) 23%, RGBA (0,0,0,0.70.70) 100%);   

But again, I do not know how to make this custom UIView subclass.

I will not be disturbed with core graphics, so I will use CAGradientLayer .

  1. Override + + + in your class

      + (class) layer class {return [CAGRD and LEA class]; }    
  2. To redefine the layer property in the interface to use this class.

      @property (nonatomic, read-only, retaining) CAGradientLayer * Layer;    
  3. Set color and other attributes.

      self.layer.colors = gradientColors; Self.layer.locations = gradientLocations; // but at the same time as `NSARRA` the self.layer.startPoint = startpoint; // 0 to 1 from self.layer.endPoint = endPoint; // to 0 to 1      

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -