Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

根据多个Range设置字体颜色时,只有最后一个生效 #59

Open
TouchGuoGuo opened this issue Apr 3, 2023 · 3 comments
Open

Comments

@TouchGuoGuo
Copy link

使用该方法public mutating func set(attributes: [Attribute], range: NSRange)设置字体颜色 在多个range的情况下只有最后一个生效

@lixiang1994
Copy link
Owner

等价于调用

func setAttributes(_ attrs: [NSAttributedString.Key : Any]?, range: NSRange)

你可以用

public mutating func add(attributes: [Attribute], range: NSRange) {

@EdgarDegas
Copy link

这个库,按照作者的回复,应该是基于 NSAttributedString,所以在确定range的时候,应该先将Swift.String转化成NSString。比如:

let length = "🤔".count
let range = NSRange(location: 0, length: length)

应该改成:

let length = ("🤔" as NSString).length
let range = NSRange(location: 0, length: length)

我脱机敲的,不知道准不准确。

@lixiang1994
Copy link
Owner

或者可以用"🤔".utf8.count 等于 ("🤔" as NSString).length

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants