Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何制作带有阴影的半透明按钮?_Ios_Objective C_Core Graphics_Shadow - Fatal编程技术网

Ios 如何制作带有阴影的半透明按钮?

Ios 如何制作带有阴影的半透明按钮?,ios,objective-c,core-graphics,shadow,Ios,Objective C,Core Graphics,Shadow,我有一个UIButton,需要是白色和50%透明的。同时我需要影子。但阴影是一个矩形,可以通过按钮背景看到。有可能用这个做点什么吗 我现在拥有的代码是: self.WhiteBtn.backgroundColor = [UIColor colorWithRed:255 green:255 blue:255 alpha:0.9]; self.WhiteBtn.opaque = NO; self.WhiteBtn.clipsToBounds = NO; self.WhiteBtn.layer.s

我有一个UIButton,需要是白色和50%透明的。同时我需要影子。但阴影是一个矩形,可以通过按钮背景看到。有可能用这个做点什么吗

我现在拥有的代码是:

self.WhiteBtn.backgroundColor = [UIColor colorWithRed:255 green:255 blue:255 alpha:0.9];
self.WhiteBtn.opaque = NO;

self.WhiteBtn.clipsToBounds = NO;

self.WhiteBtn.layer.shadowColor = [UIColor blackColor].CGColor;
self.WhiteBtn.layer.shadowOpacity = 0.5;
self.WhiteBtn.layer.shadowRadius = 5;
self.WhiteBtn.layer.shadowOffset = CGSizeMake(0,0);

最初有两个问题:阴影的形状(最初是矩形的)和按钮背景颜色与阴影颜色混合。此外,UIColor初始值设定项接受[0.0,1.0]范围内的所有参数。最后,我做了一些调整,得到了这个结果(请参见下面的代码和示例按钮)。 代码:

示例按钮:

    let shadowPathWidth: CGFloat = 1.0 // fine tune your shadow's width with this
    let layerAndShadowRadius: CGFloat = 5.0 //and its radius with this

    WhiteBtn.backgroundColor = UIColor(red:1, green:1, blue:1, alpha:0.9)
    WhiteBtn.layer.cornerRadius = layerAndShadowRadius
    WhiteBtn.layer.shadowPath = CGPathCreateCopyByStrokingPath(CGPathCreateWithRoundedRect(WhiteBtn.bounds, layerAndShadowRadius, layerAndShadowRadius, nil), nil, shadowPathWidth, CGLineCap.Round, CGLineJoin.Bevel, 0.0)

    WhiteBtn.layer.shadowOpacity = 1.0;
    WhiteBtn.layer.shadowOffset = CGSizeMake(0,0)