ios - 文本阴影 - iOS,swift 3.0

标签 ios swift3 uilabel border

我正在尝试使阴影尺寸变大一点,但我做不到。

到目前为止:

findAPlace.titleLabel?.layer.shadowOffset = CGSize(width: -1, height: 1)
findAPlace.titleLabel?.layer.shouldRasterize = true
findAPlace.titleLabel?.layer.shadowRadius = 1
findAPlace.titleLabel?.layer.shadowOpacity = 1
findAPlace.titleLabel?.layer.shadowColor = UIColor(red:0.07, green:0.07, blue:0.07, alpha:1.0).cgColor

如何将阴影缩放到比文本本身大?

像这样。

example

也许可以使用边框,我的文本是 UIButton 的标题!!!我希望它围绕着 uiButton 的文本

最佳答案

你可以这样做

实际上你需要使用 setTitleShadowColor 而不是 titleLabel?.layer.shadowColor

这里是完整的工作代码

    let btnTemp = UIButton(type: .custom)
    btnTemp.frame = CGRect(x: 50, y: 200, width: 150, height: 40)
    btnTemp.setTitle("Hello", for: .normal)
    btnTemp.titleLabel?.layer.shouldRasterize = true
    btnTemp.titleLabel?.layer.shadowRadius = 1.0
    btnTemp.titleLabel?.layer.shadowOpacity = 1.0
    btnTemp.setTitleColor(UIColor.blue, for: .normal)
    btnTemp.backgroundColor = UIColor.gray
    btnTemp.titleLabel?.shadowOffset = CGSize(width: -1, height: 1)
    btnTemp.setTitleShadowColor(UIColor(red:0.07, green:0.07, blue:0.07, alpha:1.0), for: .normal)
    self.view.addSubview(btnTemp)

希望对你有帮助

输出:

enter image description here

关于ios - 文本阴影 - iOS,swift 3.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44257716/

相关文章:

带有 UIScrollview 的 iOS 自动布局 : Why does content view of scroll view not fill the scroll view?

ios - Swift 如何修改从手机相机拍摄的图像中的 exif 信息

iphone - 以编程方式将 UILabel 添加到工具栏

objective-c - 如何循环 iOS UILabel 以显示博客文章的多条评论?

iphone - 通过代码设置 UILabel - 字体 - 生成错误 - iPhone

ios - 基于特定顺序的Sqlite排序

ios - 只要计算正在运行,就禁用设备方向通知

ios - 在 Swift 3 中从 UIPageViewController 中删除黑边

ios - 删除单元格后使用自定义布局调整 UICollectionView 的大小

ios - Alamofire 无法访问 json 响应的键