您的位置:首页 > 移动开发 > IOS开发

[10秒学会] - iOS终结 View阴影

2016-04-07 00:00 405 查看
摘要: [10秒学会] - iOS终结 View阴影

效果:


代码及其简单 用到背景图片 传不上很奇怪 我是下载苏宁项目用到的图片 需要的可以联系我

UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, YLScreenW, 80)];
imageView.image = [UIImage imageNamed:@"eightBanner_topLayer"]; //苏宁的就是这个名字 我找了一会-_-!
imageView.alpha = 0.5;
[self.view addSubview:imageView];

/*  这算是阴影的各种方式了吧
UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:imageView.bounds];
imageView.layer.masksToBounds = NO;
imageView.layer.shadowColor = [UIColor blackColor].CGColor;
imageView.layer.shadowOffset = CGSizeMake(0.0f, 5.0f);
imageView.layer.shadowOpacity = 0.5f;
imageView.layer.shadowPath = shadowPath.CGPath;

CALayer *layer = [CALayer layer];
layer.backgroundColor = [[UIColor blackColor] CGColor];//设置背景色
layer.frame = CGRectMake(100, 100, 100,10);//层设置为图片大小
layer.contents = (id)[[UIImage imageNamed:@"eightBanner_topLayer" ]CGImage];//层的内容设置为图片
layer.position = CGPointMake(100 , 100);//层在view的位置
[self.view.layer addSublayer:layer];//将层加到当前View的默认layer下
*/

/*

//  创建 UIView 用来承载渐变色
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 100)];
[self.view addSubview:myView];

//  创建 CAGradientLayer 对象
CAGradientLayer *gradientLayer = [CAGradientLayer layer];

//  设置 gradientLayer 的 Frame
gradientLayer.frame = myView.bounds;

//  创建渐变色数组,需要转换为CGColor颜色
gradientLayer.colors = @[(id)[UIColor whiteColor].CGColor,
(id)[UIColor blackColor].CGColor
];

//  设置三种颜色变化点,取值范围 0.0~1.0
gradientLayer.locations = @[@(0.1f) ,@(1.0f)];

//  设置渐变颜色方向,左上点为(0,0), 右下点为(1,1)
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(0, 1);

//  添加渐变色到创建的 UIView 上去
[myView.layer addSublayer:gradientLayer];
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  View阴影