How do I create a UIColor from RGBA?

Your values are incorrect, you need to divide each color value by 255.0. [UIColor colorWithRed:66.0f/255.0f green:79.0f/255.0f blue:91.0f/255.0f alpha:1.0f]; The docs state: + (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha Parameters red The red component of the color object, specified as a value from 0.0 to 1.0. green The green component of the color object, specified as a … Read more

Can I set the `attributedText` property of `UILabel`

Here is a complete example of how to use an attributed text on a label: NSString *redText = @”red text”; NSString *greenText = @”green text”; NSString *purpleBoldText = @”purple bold text”; NSString *text = [NSString stringWithFormat:@”Here are %@, %@ and %@”, redText, greenText, purpleBoldText]; // If attributed text is supported (iOS6+) if ([self.label respondsToSelector:@selector(setAttributedText:)]) { … Read more

How to get height for NSAttributedString at a fixed width

-[NSAttributedString boundingRectWithSize:options:] You can specify NSStringDrawingUsesDeviceMetrics to get union of all glyph bounds. Unlike -[NSAttributedString size], the returned NSRect represents the dimensions of the area that would change if the string is drawn. As @Bryan comments, boundingRectWithSize:options: is deprecated (not recommended) in OS X 10.11 and later. This is because string styling is now dynamic … Read more

NSAttributedString, change the font overall BUT keep all other attributes?

Since rmaddy’s answer did not work for me (f.fontDescriptor.withFace(font.fontName) does not keep traits like bold), here is an updated Swift 4 version that also includes color updating: extension NSMutableAttributedString { func setFontFace(font: UIFont, color: UIColor? = nil) { beginEditing() self.enumerateAttribute( .font, in: NSRange(location: 0, length: self.length) ) { (value, range, stop) in if let f … Read more

Core Text – NSAttributedString line height done right?

Objective-C NSInteger strLength = [myString length]; NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init]; [style setLineSpacing:24]; [attString addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, strLength)]; Swift 5 let strLength = myString.length() var style = NSMutableParagraphStyle() style.lineSpacing = 24 attString.addAttribute(.paragraphStyle, value: style, range: NSRange(location: 0, length: strLength))

How to calculate the height of an NSAttributedString with given width in iOS 6 [duplicate]

Option 2 does work in iOS with the proper parameters. NSAttributedString *attrStr = … // your attributed string CGFloat width = 300; // whatever your desired width is CGRect rect = [attrStr boundingRectWithSize:CGSizeMake(width, 10000) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil]; Without the proper values for the options parameter you will get the wrong height. It is also … Read more

how to append Attributed Text String with Attributed String in Swift

Use NSMutableAttributedString to achieve that. Example Swift 5 let yourAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 15)] let yourOtherAttributes = [NSAttributedString.Key.foregroundColor: UIColor.red, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 25)] let partOne = NSMutableAttributedString(string: “This is an example “, attributes: yourAttributes) let partTwo = NSMutableAttributedString(string: “for the combination of Attributed String!”, attributes: yourOtherAttributes) partOne.append(partTwo) Swift 3 let yourAttributes = [NSForegroundColorAttributeName: UIColor.black, … Read more

iOS NSAttributedString on UIButton

It looks to me like you forgot in your code to use the “style” object that you set up.. you just instantiated it. You should modify your code to look like this: NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; [style setAlignment:NSTextAlignmentCenter]; [style setLineBreakMode:NSLineBreakByWordWrapping]; UIFont *font1 = [UIFont fontWithName:@”HelveticaNeue-Medium” size:20.0f]; UIFont *font2 = [UIFont fontWithName:@”HelveticaNeue-Light” size:20.0f]; NSDictionary … Read more

Center two fonts with different different sizes vertically in an NSAttributedString

I’d say the easiest thing to do is just manipulate the NSBaselineOffsetAttributeName attribute for the text in question: 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. To center, you’d take the difference between height … Read more

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