ios - NSRangePointer 错误 swift

标签 ios swift swift3 nsattributedstring

这就是我要实现的目标:

var range : NSRange? = NSMakeRange(0, (attributedString?.length)!)
attributedString?.attribute(NSFontAttributeName: UIFont.fontNames(forFamilyName: "OpenSans-Regular"), at: 1, effectiveRange: &range) 

在第二行,我收到一个编译时错误:

Argument labels '(NSFontAttributeName:, at:, effectiveRange:)' do not match any available overloads

最佳答案

你需要:

var range = NSRange(location: 0, length: attributedString?.length)
let font = attributedString?.attribute(NSFontAttributeName, at: 1, effectiveRange: &range)

第一个参数就是您要检查的属性。您不传递特定字体。此方法将告诉您要在指定位置找到字体。

关于ios - NSRangePointer 错误 swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39795842/

相关文章:

ios - 单击按钮时退出应用程序 - iOS

ios - Swift 3 - 从 xib 加载的 UITableViewCell - 自动布局和高度不正确

swift - 代理包装 iOS 14 Logger 类

ios - 如何在 Swift 4 中将 2 个 boolean 组合在一起

ios - Swift 3 遍历类数组

ios - NavigationBar 背景图片适用于 iOS 10 XCode 8.1 Swift 3.0

ios - 没有得到 FBSDKtoken

ios - Swift UIActivityViewController Image&Url Share 不适用于 FB

swift - NSFont.TextStyleOptionKey 中可以使用哪些值

ios - "Core Data could not fulfill a fault"对于在主线程上的 appDelegate managedObjectContext 中创建的对象