简体   繁体   English

带边框和阴影的圆形按钮

[英]Round button with border and shadow

在此处输入图片说明

What would be the best way to create a button such as the one in the image?创建按钮(例如图像中的按钮)的最佳方法是什么? I tried:我试过:

            self.button.layer.shadowColor = UIColor.redColor.CGColor;
            self.button.layer.shadowRadius = 30.0f;
            self.button.layer.shadowOpacity = 1.0f;
            self.button.layer.shadowOffset = CGSizeMake(0.0f, 30.0f);
            self.button.clipsToBounds = NO;

            [self.button setNeedsDisplay];

But this just add a minor very blury shadow not at all like in the image.但这只是添加了一个非常模糊的小阴影,与图像中完全不同。

Hey @user426132 set UIbutton background image and Try this code嘿@user426132 设置 UIbutton 背景图像并尝试此代码

For Objective-c对于Objective-c

self.button.layer.cornerRadius = self.button.frame.size.width / 2;
self.button.layer.masksToBounds = false;
self.button.layer.shadowColor = UIColor.grayColor.CGColor;
self.button.layer.shadowOpacity = 1.0;
self.button.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);
self.button.layer.shadowRadius = 10;
self.button.layer.shouldRasterize = true;
self.button.layer.rasterizationScale = UIScreen.mainScreen.scale;

For Swift 4.2对于Swift 4.2

    self.btnShadow.layer.cornerRadius =  self.btnShadow.frame.size.width / 2
    self.btnShadow.layer.masksToBounds = false
    self.btnShadow.layer.shadowColor = UIColor.black.cgColor
    self.btnShadow.layer.shadowOpacity = 1.0
    self.btnShadow.layer.shadowOffset = CGSize(width: 0, height: 0)
    self.btnShadow.layer.shadowRadius = 10
    self.btnShadow.layer.shouldRasterize = true
    self.btnShadow.layer.rasterizationScale = UIScreen.main.scale

Output is here输出在这里在此处输入图片说明 in black cross is image黑色十字是图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM