ios UIView用于完整的viewController框架

时间:2017-11-27 06:12:14

标签: ios objective-c swift

我是ios的初学者,我想像Image一样创建一个UIVew。您可以在附加图像中观察从一个地方到另一个地方的白色。我怎样才能实现它。提前谢谢。

enter image description here

1 个答案:

答案 0 :(得分: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;
}

修改

这将创建一个渐变视图,上侧白色和下侧是黑色。如果您想要top-bottomleft-right,则必须添加startPointendPoint

只需添加两行

gradient.startPoint = CGPointMake(1.0, 0.0);
gradient.endPoint = CGPointMake(0.0, 0.0);