Ios 如何正确应用Swift中非拉丁字符的笔划?
我正在做一个将文本属性应用于UIlabel文本的项目。我使用常见的NSAttributedString键基本上应用strokeColor、strokeWidth和foregroundColor来生成所需的大纲效果。这个问题出现在非拉丁字符上,比如阿拉伯语,字母是单独突出显示的,而不是整个作品。字母通常是用阿拉伯语连接的,而未连接的英语字母是用空格隔开的。我附上了我正在处理的示例,其中包含问题的屏幕截图和期望的结果。我将感谢您的支持和建议Ios 如何正确应用Swift中非拉丁字符的笔划?,ios,swift,xcode,text,nsattributedstring,Ios,Swift,Xcode,Text,Nsattributedstring,我正在做一个将文本属性应用于UIlabel文本的项目。我使用常见的NSAttributedString键基本上应用strokeColor、strokeWidth和foregroundColor来生成所需的大纲效果。这个问题出现在非拉丁字符上,比如阿拉伯语,字母是单独突出显示的,而不是整个作品。字母通常是用阿拉伯语连接的,而未连接的英语字母是用空格隔开的。我附上了我正在处理的示例,其中包含问题的屏幕截图和期望的结果。我将感谢您的支持和建议 let quote = "الكتابة على الصو
let quote = "الكتابة على الصور بخطوط جميلة"
//let font = UIFont.systemFon.selft(ofSize: 50)
let attributes: [NSAttributedString.Key: Any] = [
.strokeColor: UIColor.green,
.strokeWidth: -3.0,
.foregroundColor: UIColor.red,
.font: UIFont(name: "Georgia-Bold", size: 40)!,
]
let attributedQuote = NSAttributedString(string: quote, attributes: attributes)
TextLabel.attributedText = attributedQuote
有问题的结果:
预期结果:
快速查看一下,并将其与css的类似输出进行比较,我认为您需要使用两个相互重叠的标签层 尝试一下:
let backLabel = UILabel()
let frontLabel = UILabel()
backLabel.translatesAutoresizingMaskIntoConstraints = false
frontLabel.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(backLabel)
view.addSubview(frontLabel)
NSLayoutConstraint.activate([
backLabel.topAnchor.constraint(equalTo: view.topAnchor, constant: 100.0),
backLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20.0),
backLabel.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20.0),
frontLabel.topAnchor.constraint(equalTo: backLabel.topAnchor),
frontLabel.leadingAnchor.constraint(equalTo: backLabel.leadingAnchor),
frontLabel.trailingAnchor.constraint(equalTo: backLabel.trailingAnchor),
])
let quote = "الكتابة على الصور بخطوط جميلة"
var attributes: [NSAttributedString.Key: Any] = [
.strokeColor: UIColor.green,
.strokeWidth: 12.0,
.foregroundColor: UIColor.red,
.font: UIFont(name: "Georgia-Bold", size: 40)!,
]
var attributedQuote = NSAttributedString(string: quote, attributes: attributes)
backLabel.attributedText = attributedQuote
attributes = [
.strokeColor: UIColor.green,
.strokeWidth: 0,
.foregroundColor: UIColor.red,
.font: UIFont(name: "Georgia-Bold", size: 40)!,
]
attributedQuote = NSAttributedString(string: quote, attributes: attributes)
frontLabel.attributedText = attributedQuote
结果:
快速查看一下,并将其与css的类似输出进行比较,我认为您需要使用两个相互重叠的标签层 尝试一下:
let backLabel = UILabel()
let frontLabel = UILabel()
backLabel.translatesAutoresizingMaskIntoConstraints = false
frontLabel.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(backLabel)
view.addSubview(frontLabel)
NSLayoutConstraint.activate([
backLabel.topAnchor.constraint(equalTo: view.topAnchor, constant: 100.0),
backLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20.0),
backLabel.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20.0),
frontLabel.topAnchor.constraint(equalTo: backLabel.topAnchor),
frontLabel.leadingAnchor.constraint(equalTo: backLabel.leadingAnchor),
frontLabel.trailingAnchor.constraint(equalTo: backLabel.trailingAnchor),
])
let quote = "الكتابة على الصور بخطوط جميلة"
var attributes: [NSAttributedString.Key: Any] = [
.strokeColor: UIColor.green,
.strokeWidth: 12.0,
.foregroundColor: UIColor.red,
.font: UIFont(name: "Georgia-Bold", size: 40)!,
]
var attributedQuote = NSAttributedString(string: quote, attributes: attributes)
backLabel.attributedText = attributedQuote
attributes = [
.strokeColor: UIColor.green,
.strokeWidth: 0,
.foregroundColor: UIColor.red,
.font: UIFont(name: "Georgia-Bold", size: 40)!,
]
attributedQuote = NSAttributedString(string: quote, attributes: attributes)
frontLabel.attributedText = attributedQuote
结果:
谢谢!我尝试了这个选项,如果工作如预期!帮我节省了很多时间,伙计!再次感谢汉克斯!我尝试了这个选项,如果工作如预期!帮我节省了很多时间,伙计!再次感谢有人尝试使用cgContext的core graphics解决此问题?有人尝试使用cgContext的core graphics解决此问题吗?