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

Set spacing between lines. #1260

Open
0xifarouk opened this issue Oct 8, 2022 · 0 comments
Open

Set spacing between lines. #1260

0xifarouk opened this issue Oct 8, 2022 · 0 comments

Comments

@0xifarouk
Copy link

0xifarouk commented Oct 8, 2022

How can I achieve apple spacing between lines?
Exmaple

Code I am using:

public func returnAttributedStringForHTMLString(
    fontFamily: String,
    fontName: String,
    fontSize: CGFloat,
    textColor: UIColor,
    textAlignment: CTTextAlignment
  ) -> NSMutableAttributedString {
    let encodedData = self.data(using: String.Encoding.utf8)!
    let options = [
      DTDefaultFontFamily: fontFamily,
      DTDefaultFontName: fontName,
      DTDefaultFontSize: fontSize,
      DTDefaultTextColor: textColor,
      DTDefaultTextAlignment: NSNumber(value: textAlignment.rawValue),
    ] as [String : Any]
    let builder = DTHTMLAttributedStringBuilder(html: encodedData, options: options, documentAttributes: nil)
    var returnValue: NSAttributedString?
    returnValue = builder?.generatedAttributedString()
    if returnValue != nil {
      // needed to show link highlighting
      let mutable = NSMutableAttributedString(attributedString: returnValue!)
      mutable.removeAttribute(NSAttributedString.Key.foregroundColor, range: NSMakeRange(0, mutable.length))
      return mutable
    } else {
      return NSMutableAttributedString(string: "")
    }
  }

Call site:

    Text(
      AttributedString(
        html.returnAttributedStringForHTMLString(
          fontFamily: "SF Text",
          fontName: "SF Text Regular",
          fontSize: 17,
          textColor: .label,
          textAlignment: .left
        )
      )
    )

Also I want to use default apple font that comes with the system, I am using "SF Text" for fontFamily and "SF Text Regular" for fontName, is this correct? or if there is a way to omit the parameters and automatically use the system font.

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

1 participant