【发布时间】:2016-05-09 03:26:02
【问题描述】:
我想在我的 UILabel 中增加阴影的传播,但我找不到这样做的属性。我在下面添加了一张照片来说明问题。
顶部标签是我能够在 Photoshop 中创建的所需效果。底部标签说明了我能够在 iOS 中找到的属性。这是我用于底部标签的代码。
let bottomLabel = UILabel(frame: CGRectMake(0, 0, maxWidth, 18))
bottomLabel.backgroundColor = UIColor.clearColor()
bottomLabel.textColor = UIColor.whiteColor()
bottomLabel.font = UIFont.boldSystemFontOfSize(16)
bottomLabel.text = title
bottomLabel.textAlignment = .Center
bottomLabel.numberOfLines = 1
bottomLabel.layer.shadowOffset = CGSize(width: 0, height: 0)
bottomLabel.layer.shadowOpacity = 1
bottomLabel.layer.shadowRadius = 2
我确实找到了使用第二个标签作为阴影的建议,但这并没有给出预期的结果。这是该标签的代码。
let bottomLabelShadow = UILabel(frame: CGRectMake(0, 1, maxWidth, 18))
bottomLabelShadow.backgroundColor = UIColor.clearColor()
bottomLabelShadow.textColor = UIColor.blackColor()
bottomLabelShadow.font = UIFont.boldSystemFontOfSize(16)
bottomLabelShadow.text = title
bottomLabelShadow.textAlignment = .Center
bottomLabelShadow.numberOfLines = 1
bottomLabelShadow.layer.shadowOffset = CGSize(width: 0, height: 0)
bottomLabelShadow.layer.shadowOpacity = 1
bottomLabelShadow.layer.shadowRadius = 2
【问题讨论】:
-
其实有一篇关于阴影的好文章makeapppie.com/2015/05/19/…
-
嗨蒂姆,你得到解决方案了吗,我正在寻找相同的解决方案