![]() you need to define the length for each oneĮxamples: let attStr1 = NSMutableAttributedString().characterSubscriptAndSuperscript( you define the length in the length array ![]() Range:NSRange(location:scriptedCharaterLocation, NSForegroundColorAttributeName:UIColor.black], NSBaselineOffsetAttributeName:baseLineOffset, Now set attributes starting from the character aboveĪtAttributes([NSFontAttributeName:scriptFont, Get to location of the first character enumerated the array of first characters to subscriptįor (theLength,aCharacter) in characters.enumerated() enumerated the main text characters using a for loopįor (i,c) in () Let baseLineOffset = offSet * type.rawValue the enum is used here declaring the required offset Let attString = NSMutableAttributedString(string:string, attributes: ) Define Attributes of the text body, this part can be removed of the function Let scriptFont = UIFont.boldSystemFont(ofSize: scriptFontSize) Let stringFont = UIFont.boldSystemFont(ofSize: fontSize) Define the fonts you want to use and sizes Set The Paragraph aligmnet, you can ignore this part and delet off the function Let paraghraphStyle = NSMutableParagraphStyle() you can modify it by skipping the parts that are not essential to you extension NSMutableAttributedStringįunc characterSubscriptAndSuperscript(string:String,Īlignment:NSTextAlignment)-> NSMutableAttributedString ![]() I wrote the following extension or you can use it as a function, it is working well for me. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |