Type ‘NSAttributedStringKey’ (aka ‘NSString’) has no member ‘font’

Note: Ensure swift language version of your project. Here is how you can see/check your swift language version. You have two options as solution to your query: If your project has Swift versio 4.0 – You should choose/download POD compatible to your project’s swift language (Share me POD info and swift version, so I can … 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 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 entire text string in NSAttributedString without modifying other attributes

You can use NSMutableAttributedString and just update the string, the attributes won’t change. Example: NSMutableAttributedString *mutableAttributedString = [[NSMutableAttributedString alloc] initWithString:@”my string” attributes:@{NSForegroundColorAttributeName: [UIColor blueColor], NSFontAttributeName: [UIFont systemFontOfSize:20]}]; //update the string [mutableAttributedString.mutableString setString:@”my new string”];

Transform an NSAttributedString to plain text

If I understand you correctly you have an NSData, say data, containing an encoded NSAttributedString. To reverse the process: NSAttributedString *nas = [[NSAttributedString alloc] initWithData:data options:nil documentAttributes:NULL error:NULL]; and to get the plain text without attributes you then do: NSString *str = [nas string];

Make link in UILabel.attributedText *not* blue and *not* underlined

So I ended up using TTTAttributedLabel: -(void)createLinkFromWord:(NSString*)word withColor:(UIColor*)color atRange:(NSRange)range{ NSMutableAttributedString* newTextWithLinks = [self.label.attributedText mutableCopy]; NSURL *url = [NSURL URLWithString:@”http://www.reddit.com”]; self.label.linkAttributes = @{NSForegroundColorAttributeName: color, NSUnderlineStyleAttributeName: @(NSUnderlineStyleNone)}; [self.label addLinkToURL:url withRange:range]; } I found that OHAttributedLabel actually does have methods to set links and declare colors and underline styles for those links. However, I wanted the links to … Read more

How to set font size on NSAttributedString

let myString = “Swift Attributed String” let myAttribute = [ NSForegroundColorAttributeName: UIColor.blue ] let myAttrString = NSAttributedString(string: myString, attributes: myAttribute) // set attributed text on a UILabel myLabel.attributedText = myAttrString Font let myAttribute = [ NSFontAttributeName: UIFont(name: “Chalkduster”, size: 18.0)! ] Shadow let myShadow = NSShadow() myShadow.shadowBlurRadius = 3 myShadow.shadowOffset = CGSize(width: 3, height: 3) … Read more

NSAttributedString ignores Autoshrink and numberOfLines for UILabel (iOS 6)

I found a way to do this: label.adjustsFontSizeToFitWidth = true label.attributedText = attributedString label.lineBreakMode = .ByTruncatingTail // this did the trick! It only works if the third line is set after setting the attributed string. It seems like the attributed string overrides line break behavior when set (among other things).

centering text in a UILabel with an NSAttributedString

You need to create a paragraph style specifying center alignment, and set that paragraph style as an attribute on your text. Example playground: import UIKit import PlaygroundSupport let style = NSMutableParagraphStyle() style.alignment = NSTextAlignment.center let richText = NSMutableAttributedString(string: “Going through some basic improvements to a application I am working on. Still new to the iOS … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)