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

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?

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.

How to align an image and string of an attributed String?
 
 
Q