NSAttributedString

extension NSAttributedString: AttributedStringParameter, StringParameter
  • Undocumented

    Declaration

    Swift

    public var attributedStringValue: NSAttributedString { get }
  • Undocumented

    Declaration

    Swift

    public var stringValue: String { get }

NSAttributedString+Foundation

  • 获取全局样式(index为0的属性)

    Declaration

    Swift

    public var fw_attributes: [NSAttributedString.Key : Any]? { get }
  • NSAttributedString对象转换为html字符串

    Declaration

    Swift

    public func fw_htmlString() -> String?
  • 计算所占尺寸,需设置Font等

    Declaration

    Swift

    public var fw_textSize: CGSize { get }
  • 计算在指定绘制区域内所占尺寸,需设置Font等

    Declaration

    Swift

    public func fw_textSize(drawSize: CGSize) -> CGSize
  • html字符串转换为NSAttributedString对象。如需设置默认字体和颜色,请使用addAttributes方法或附加CSS样式

    Declaration

    Swift

    public static func fw_attributedString(htmlString: String) -> `Self`?
  • 图片转换为NSAttributedString对象,可实现行内图片样式。其中bounds.x会设置为间距,y常用算法:(font.capHeight - image.size.height) / 2.0

    Declaration

    Swift

    public static func fw_attributedString(image: UIImage?, bounds: CGRect) -> NSAttributedString
  • 快速创建NSAttributedString并指定单个高亮部分文字和样式,链接设置NSLinkAttributeName|URL属性即可

    Declaration

    Swift

    public static func fw_attributedString(string: String, attributes: [NSAttributedString.Key : Any]?, highlight: String, highlightAttributes: [NSAttributedString.Key : Any]?) -> NSAttributedString
  • 快速创建NSAttributedString并指定所有高亮部分文字和样式,链接设置NSLinkAttributeName|URL属性即可

    Declaration

    Swift

    public static func fw_attributedString(string: String, attributes: [NSAttributedString.Key : Any]?, highlights: [String : [NSAttributedString.Key : Any]]) -> NSAttributedString
  • 快速创建NSAttributedString,自定义字体和颜色

    Declaration

    Swift

    public static func fw_attributedString(_ string: String, font: UIFont?, textColor: UIColor? = nil, attributes: [NSAttributedString.Key : Any]? = nil) -> Self
  • 快速创建NSAttributedString,自定义字体、颜色、行高、对齐方式和换行模式

    Declaration

    Swift

    public static func fw_attributedString(_ string: String, font: UIFont?, textColor: UIColor?, lineHeight: CGFloat, textAlignment: NSTextAlignment = .left, lineBreakMode: NSLineBreakMode = .byWordWrapping, attributes: [NSAttributedString.Key : Any]? = nil) -> Self
  • 快速创建指定行高、对齐方式和换行模式的段落样式对象

    Declaration

    Swift

    public static func fw_paragraphStyle(lineHeight: CGFloat, textAlignment: NSTextAlignment = .left, lineBreakMode: NSLineBreakMode = .byWordWrapping) -> NSMutableParagraphStyle
  • html字符串转换为NSAttributedString对象,可设置默认系统字体和颜色(附加CSS方式)

    Declaration

    Swift

    public static func fw_attributedString(htmlString string: String, defaultAttributes: [NSAttributedString.Key : Any]?) -> `Self`?
  • html字符串转换为NSAttributedString主题对象,可设置默认系统字体和动态颜色,详见ThemeObject

    Declaration

    Swift

    public static func fw_themeObject(htmlString: String, defaultAttributes: [NSAttributedString.Key : Any]?) -> ThemeObject<NSAttributedString>
  • 获取颜色对应CSS字符串(rgb|rgba格式)

    Declaration

    Swift

    public static func fw_cssString(color: UIColor) -> String
  • 获取系统字体对应CSS字符串(family|style|weight|size)

    Declaration

    Swift

    public static func fw_cssString(font: UIFont) -> String