Superscript cents in an attributed string

You have to use NSBaselineOffsetAttributedName. From the doc: NSBaselineOffsetAttributeName The value of this attribute is an NSNumber object containing a floating point value indicating the character’s offset from the baseline, in points. The default value is 0. Available in iOS 7.0 and later. From your example: [buyString addAttribute:NSBaselineOffsetAttributeName value:@(10.0) range:NSMakeRange(2, buyString.length – 2)]; You may … Read more

Convert attributed string, to, “simple” tagged html

According to the documentation of enumerateAttribute:inRange:options:usingBlock:, especially the Discussion part which states: If this method is sent to an instance of NSMutableAttributedString, mutation (deletion, addition, or change) is allowed, as long as it is within the range provided to the block; after a mutation, the enumeration continues with the range immediately following the processed range, … Read more

ios7 font size change when create nsattributedstring from html

I also faced this issue, I fixed it by iterating to the attributes and reseting the old font size as follows NSMutableAttributedString *res = [attributedText mutableCopy]; [res beginEditing]; [res enumerateAttribute:NSFontAttributeName inRange:NSMakeRange(0, res.length) options:0 usingBlock:^(id value, NSRange range, BOOL *stop) { if (value) { UIFont *oldFont = (UIFont *)value; UIFont *newFont = [oldFont fontWithSize:15]; [res addAttribute:NSFontAttributeName … Read more

Looping Through NSAttributedString Attributes to Increase Font SIze

Something like this should work: NSMutableAttributedString *res = [self.richTextEditor.attributedText mutableCopy]; [res beginEditing]; __block BOOL found = NO; [res enumerateAttribute:NSFontAttributeName inRange:NSMakeRange(0, res.length) options:0 usingBlock:^(id value, NSRange range, BOOL *stop) { if (value) { UIFont *oldFont = (UIFont *)value; UIFont *newFont = [oldFont fontWithSize:oldFont.pointSize * 2]; [res removeAttribute:NSFontAttributeName range:range]; [res addAttribute:NSFontAttributeName value:newFont range:range]; found = YES; } … Read more

NSAttributedString superscript styling

The following code seems to do the trick: UIFont *fnt = [UIFont fontWithName:@”Helvetica” size:20.0]; NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@”GGG®GGG” attributes:@{NSFontAttributeName: [fnt fontWithSize:20]}]; [attributedString setAttributes:@{NSFontAttributeName : [fnt fontWithSize:10] , NSBaselineOffsetAttributeName : @10} range:NSMakeRange(3, 1)];

How to underline a UILabel in swift?

You can do this using NSAttributedString Example: let underlineAttribute = [NSAttributedString.Key.underlineStyle: NSUnderlineStyle.thick.rawValue] let underlineAttributedString = NSAttributedString(string: “StringWithUnderLine”, attributes: underlineAttribute) myLabel.attributedText = underlineAttributedString EDIT To have the same attributes for all texts of one UILabel, I suggest you to subclass UILabel and overriding text, like that: Swift 5 Same as Swift 4.2 but: You should prefer … Read more

Is it possible to change color of single word in UITextView and UITextField

Yes you need to use NSAttributedString for that, find the RunningAppHere. Scan through the word and find the range of your word and change its color. EDIT: – (IBAction)colorWord:(id)sender { NSMutableAttributedString * string = [[NSMutableAttributedString alloc]initWithString:self.text.text]; NSArray *words=[self.text.text componentsSeparatedByString:@” “]; for (NSString *word in words) { if ([word hasPrefix:@”@”]) { NSRange range=[self.text.text rangeOfString:word]; [string addAttribute:NSForegroundColorAttributeName … Read more

boundingRectWithSize for NSAttributedString returning wrong size

Looks like you weren’t providing the correct options. For wrapping labels, provide at least: CGRect paragraphRect = [attributedText boundingRectWithSize:CGSizeMake(300.f, CGFLOAT_MAX) options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) context:nil]; Note: if the original text width is under 300.f there won’t be line wrapping, so make sure the bound size is correct, otherwise you will still get wrong results.