当前位置: 动力学知识库 > 问答 > 编程问答 >

objective c - Manage alignment in custom font in iOS

问题描述:

I am using custom font in my code. After using it, letters are not aligned in one line which is causing UI issues.

I want to change font or label setting so that it look like below :

Any help?

网友答案:

I think, it is due to the Font style so you can set the text as NSAttributedString String and manage the Font accordingly. In that case create two NSMutableAttributedString with different Attributesand use it.

extension String    {

    func getText() -> NSAttributedString {
        let str1 = "Hello"
        let str2 = "750"

        //create attribute
        let attStr1      = NSMutableAttributedString(string: str1)
        let attFormat   = [NSFontAttributeName : UIFont.systemFontOfSize(10.0)]
        let attString   = NSMutableAttributedString(string: str2, attributes: attFormat)
        attString.appendAttributedString(attStr1)

        return attString
    }
}

Just create Attribute according to your requirement and it will work.

分享给朋友:
您可能感兴趣的文章:
随机阅读: