gpt4 book ai didi

ios - 如何在 Swift 中为我的标签添加轮廓?

转载 作者:搜寻专家 更新时间:2023-11-01 06:01:09 25 4
gpt4 key购买 nike

我是 Stackoverflow 的新手。
我目前正在使用 XCode for iOS 开发移动应用程序。
然而,我正在尝试为我的标签添加一个白色轮廓/描边,但我不知道该怎么做。我曾尝试搜索这些论坛,但无法在 swift 中找到任何解决方案。
我尝试过使用 shadow 属性,但并不令人满意。
如何在 Swift 中为我的标签添加轮廓?
编辑:文本应类似于此图片中的文本:http://cf.chucklesnetwork.com/items/7/5/7/4/4/original/yo-dawg-i-heard-you-like-captions-so-i-put-captions-of-captions.jpg

最佳答案

需要使用NSAttributedString,设置strokeColorstrokeWidth来设置轮廓,foregroundColor来设置文本颜色.试试这个:

let attrString = NSAttributedString(
string: "Write Something with Outline",
attributes: [
NSAttributedStringKey.strokeColor: UIColor.black,
NSAttributedStringKey.foregroundColor: UIColor.white,
NSAttributedStringKey.strokeWidth: -2.0,
NSAttributedStringKey.font: UIFont.systemFont(ofSize: 17.0)
]
)
yourLabel.attributedText = attrString

这将如下所示:

enter image description here

关于ios - 如何在 Swift 中为我的标签添加轮廓?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50154003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com