I am beginner for ios and I want to create a UIVew as like Image. You can observe a white color from one place to another place in the attached image. How can I achieve it. Thanks in advance.
Asked
Active
Viewed 79 times
-5
-
https://stackoverflow.com/q/23074539/1891327 – Shamas S Nov 27 '17 at 06:13
-
https://stackoverflow.com/questions/41013702/gradient-effect-on-some-portion-of-uiimageview/41014007#41014007 – jignesh Vadadoriya Nov 27 '17 at 06:21
-
Possible duplicate of [Programmatically create a UIView with color gradient](https://stackoverflow.com/questions/23074539/programmatically-create-a-uiview-with-color-gradient) – OverD Nov 27 '17 at 07:50
1 Answers
0
-(UIView *) returnGradientView {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = view.bounds;
//change your color as you like, I have used black and white
gradient.colors = @[(id)[UIColor blackColor].CGColor, (id)[UIColor whiteColor].CGColor];
[view.layer insertSublayer:gradient atIndex:0];
return view;
}
Edit
this will create an gradient view, upper side white and lower side is black. if you want to make top-bottom
or left-right
you have to add startPoint
and endPoint
just add two line
gradient.startPoint = CGPointMake(1.0, 0.0);
gradient.endPoint = CGPointMake(0.0, 0.0);

Ankur Lahiry
- 2,253
- 1
- 15
- 25