UIView 设置阴影(属性说明)

以下代码实现:

第一个图片的代码

//加阴影--任海丽编辑
    _imageView.layer.shadowColor = [UIColor blackColor].CGColor;//shadowColor阴影颜色
    _imageView.layer.shadowOffset = CGSizeMake(4,4);//shadowOffset阴影偏移,x向右偏移4,y向下偏移4,默认(0, -3),这个跟shadowRadius配合使用
    _imageView.layer.shadowOpacity = 0.8;//阴影透明度,默认0
    _imageView.layer.shadowRadius = 4;//阴影半径,默认3

第二个图片的代码

    _imageView1.layer.shadowColor = [UIColor yellowColor].CGColor;//shadowColor阴影颜色
    _imageView1.layer.shadowOffset = CGSizeMake(0,0);//shadowOffset阴影偏移,默认(0, -3),这个跟shadowRadius配合使用
    _imageView1.layer.shadowOpacity = 1;//阴影透明度,默认0
    _imageView1.layer.shadowRadius = 3;//阴影半径,默认3

    //路径阴影
    UIBezierPath *path = [UIBezierPath bezierPath];

    float width = _imageView1.bounds.size.width;
    float height = _imageView1.bounds.size.height;
    float x = _imageView1.bounds.origin.x;
    float y = _imageView1.bounds.origin.y;
    float addWH = 10;

    CGPoint topLeft      = _imageView1.bounds.origin;
    CGPoint topMiddle = CGPointMake(x+(width/2),y-addWH);
    CGPoint topRight     = CGPointMake(x+width,y);

    CGPoint rightMiddle = CGPointMake(x+width+addWH,y+(height/2));

    CGPoint bottomRight  = CGPointMake(x+width,y+height);
    CGPoint bottomMiddle = CGPointMake(x+(width/2),y+height+addWH);
    CGPoint bottomLeft   = CGPointMake(x,y+height);

    CGPoint leftMiddle = CGPointMake(x-addWH,y+(height/2));

    [path moveToPoint:topLeft];
    //添加四个二元曲线
    [path addQuadCurveToPoint:topRight
                 controlPoint:topMiddle];
    [path addQuadCurveToPoint:bottomRight
                 controlPoint:rightMiddle];
    [path addQuadCurveToPoint:bottomLeft
                 controlPoint:bottomMiddle];
    [path addQuadCurveToPoint:topLeft
                 controlPoint:leftMiddle];
    //设置阴影路径
     _imageView1.layer.shadowPath = path.CGPath;

原文链接:http://blog.csdn.net/rhljiayou/article/details/10178723

时间: 2024-08-10 01:56:56

UIView 设置阴影(属性说明)的相关文章

UIView设置阴影无效的原因之一

本想在底部的按钮设置个阴影, 代码如下: self.layer.shadowColor = [UIColor blackColor].CGColor; self.layer.shadowOffset = CGSizeMake(-5, 5); self.layer.shadowOpacity = 0.8; self.layer.shadowRadius = 10; 写完后,死活不出效果,那个纠结啊,明明代码没问题啊 最后发现,按钮没有设置背景色,把背景色设置后,就好!

UIView,UIButton,UIImageView等设置圆角,设置阴影,设置边框的方法

在iOS开发中,任何可见视图都是继承于UIView的.    继承体系中,大部分UIView的属性适用于其任何孩子. 而UIView的layer属性可以绘制UIView的各种效果.其实我们看到的View的动画实际上也是layer在绘制. 1.绘制圆角 cornerView.layer.cornerRadius = 20; cornerView.layer.masksToBounds = YES; masksToBounds防止子元素溢出父视图. 如果一个正方形要设置成圆形,代码为: corner

storyboard或者Xib给View设置边框属性(颜色,宽度,圆角)

纯代码设置Button或者其他View的边框属性 例: UIView* view = [[UIView alloc]init]; view.layer.borderWidth = 2.0; view.layer.masksToBounds = YES; view.layer.cornerRadius = 5.0; view.layer.borderColor = [UIColorredColor].CGColor; 以下提供自定义控件的时候,使用Xib,或者用sb来进行布局,那么这时候怎么来使用

UIView的常见属性和方法

- (void)viewDidLoad { [super viewDidLoad]; // 临时View UIView *temp = [[UIView alloc] init]; temp.frame = CGRectMake(0, 0, 100, 100); [self.view addSubview:temp]; //UIView的常见属性 //1. 获得自己的父控件 [temp superview]; //2. 获得自己所有的子控件对象 [temp subviews]; //3. 控件的

UIView的常用属性和方法

@start 今天练习的是UIView的常用属性,首先应该新建一个窗口和相应的根视图控制器 1 //新建一个窗口和根视图控制器 2 self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]; 3 4 //设置视图控制器 5 UIViewController *controller = [[UIViewController alloc]init]; 6 self.window.rootViewControl

UIView控件属性

UIView控件属性: 1.alpha 设置视图的透明度.默认为1. // 完全透明 view.alpha = 0; // 不透明 view.alpha = 1; 2.clipsToBounds // 默认是NO,当设置为yes时,超出当前视图的尺寸的内容和子视图不会显示. view.clipsToBounds = YES; 3.hidden // 默认是NO,当设置为yes,视图就看不见了. view.hidden = YES; 4.userInteractionEnabled // 默认为Y

关于UIView的userInteractionEnabled属性

如果父视图为ParentView包含一个Button,如果再ParentView上添加子视图ChildView,且ChildView盖住了 Button,那么Button就得到不响应了,为了让Button响应,可以设置ChildView的userInteractionEnabled = NO:最近被这个问题困扰了很久,开始想用事件传递的方法,重写类继承自UIView,最后被这简单属性搞定了.... 关于UIView的userInteractionEnabled属性,布布扣,bubuko.com

UIView之常用属性

UIView之常用属性 1. view.tag = 200; // 系统保留0-1002. view.frame = CGRectMake(20, 30, 300, 300);3. view.center = self.view.center;4. view.backgroundColor = [UIColor redColor];5. // 用户交互6. view.userInteractionEnabled = YES; // 默认为YES 1.// 旋转2. view.transform

为视图设置阴影

[alertSquare.layer setShadowColor:[UIColor blackColor].CGColor]; //阴影的不透明属性0.0-1.0,默认值为0(完全透明,没有阴影效果) [alertSquare.layer setShadowOpacity:0.4]; //设置阴影半径 [alertSquare.layer setShadowRadius:20.0f]; //设置阴影偏移量 [alertSquare.layer setShadowOffset:CGSizeMak