2016-09-30 94 views
1

这就是我想实现:NSRangePointer错误斯威夫特

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

回答

3

您需要:

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

第一个参数就是你想检查的属性。你不会传入特定的字体。这种方法会告诉你想要在指定的位置找到字体。

+0

如何添加此属性。无法找到只接受属性的NSAttributedString的重载函数 – Nitish

+0

请参阅我对您的其他问题的评论。您正在使用错误的方法来添加属性。 – rmaddy

+0

如何在documentAttributes中添加字体? – Nitish