美文网首页
iOS-UI篇一(给按钮设置阴影)

iOS-UI篇一(给按钮设置阴影)

作者: 种提莫的蘑菇 | 来源:发表于2018-11-24 11:15 被阅读0次

    话不多说直接上代码

       UIButton *changeBtn = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];//大小随便设置的,按照自己需求修改

        changeBtn.layer.shadowOffset=  CGSizeMake(1, 1);//x向右为正,y向下为正

        changeBtn.layer.shadowOpacity=0.8;//阴影的透明度

        changeBtn.layer.shadowColor=  [UIColor redColor].CGColor;//阴影的颜色

        CGRect frame = changeBtn.bounds;

        frame.origin.x= frame.origin.x+20;//向左减 向右加

         frame.origin.y= frame.origin.y+20;//向上减 向下加

         frame.size.width= frame.size.width;//阴影的宽度

         frame.size.height= frame.size.height;//阴影的高度

        changeBtn.layer.shadowPath = [[UIBezierPath bezierPathWithRect:frame] CGPath ];//设置shadowPath

    好完成!希望对你有用

    相关文章

      网友评论

          本文标题:iOS-UI篇一(给按钮设置阴影)

          本文链接:https://www.haomeiwen.com/subject/qbmtqqtx.html