1 Reply
      Latest reply on Dec 27, 2019 6:42 AM by Claude31
      mksmurali Level 1 Level 1 (0 points)

        Hi,

        How to align an image and string of an attributed String to vertical center?

        I attached an image by using NSTextAttachment()

        And i appended a string.

        The alignment of the image and the string looks like below:

        GoodNoon

         

        How to align the string to be vertically center to the image?

        • Re: How to align an image and string of an attributed String?
          Claude31 Level 8 Level 8 (8,115 points)

          set some property of paragraphStyle for the attributed String.

           

          I would try (did not test yet):

          lineHeightMultiple: CGFloat

          Try to set at 1.2 for instance

          or

          var paragraphSpacing: CGFloat

           

                  let pstyle = NSMutableParagraphStyle()
                  pstyle.lineHeightMultiple = 1.2
                  var attributes : [NSAttributedStringKey: Any] = [NSAttributedStringKey.paragraphStyle : pstyle] 

           

          Take care of the important warning:

          A paragraph style object should not be mutated after adding it to an attributed string; doing so can cause your app to crash.