How can I both stroke and fill with NSAttributedString w/ UILabel

Yes, the key is to apply a Negative value to the NSStrokeWidthAttributeName If this value is positive you will only see the stroke and not the fill. Objective-C: self.label.attributedText=[[NSAttributedString alloc] initWithString:@”string to both stroke and fill” attributes:@{ NSStrokeWidthAttributeName: @-3.0, NSStrokeColorAttributeName:[UIColor yellowColor], NSForegroundColorAttributeName:[UIColor redColor] } ]; Thanks to @cacau below: See also Technical Q&A QA1531 Swift … Read more

Replace substring of NSAttributedString with another NSAttributedString

Convert your attributed string into an instance of NSMutableAttributedString. The mutable attributed string has a mutableString property. According to the documentation: “The receiver tracks changes to this string and keeps its attribute mappings up to date.” So you can use the resulting mutable string to execute the replacement with replaceOccurrencesOfString:withString:options:range:.

Copy NSAttributedString in UIPasteBoard

I have found that when I (as a user of the application) copy rich text from a UITextView into the pasteboard, the pasteboard contains two types: “public.text”, “Apple Web Archive pasteboard type Based on that, I created a convenient category on UIPasteboard. (With heavy use of code from this answer). It works, but: The conversion … Read more

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)];