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

UINavigationBar multi-line title

Set the titleView property of the UINavigationItem. For example, in the view controller’s viewDidLoad method you could do something like: UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 480, 44)]; label.backgroundColor = [UIColor clearColor]; label.numberOfLines = 2; label.font = [UIFont boldSystemFontOfSize: 14.0f]; label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5]; label.textAlignment = UITextAlignmentCenter; label.textColor = [UIColor whiteColor]; label.text = … Read more

Animating UILabel Font Size Change

You can change the size and font of your UILabel with animation like below .. here I just put the example of how to change the font of UILabel with transform Animation .. yourLabel.font = [UIFont boldSystemFontOfSize:35]; // set font size which you want instead of 35 yourLabel.transform = CGAffineTransformScale(yourLabel.transform, 0.35, 0.35); [UIView animateWithDuration:1.0 animations:^{ … Read more

Center NSTextAttachment image next to single line UILabel

You can use the capHeight of the font. Objective-C NSTextAttachment *icon = [[NSTextAttachment alloc] init]; UIImage *iconImage = [UIImage imageNamed:@”icon.png”]; [icon setBounds:CGRectMake(0, roundf(titleFont.capHeight – iconImage.size.height)/2.f, iconImage.size.width, iconImage.size.height)]; [icon setImage:iconImage]; NSAttributedString *iconString = [NSAttributedString attributedStringWithAttachment:icon]; [titleText appendAttributedString:iconString]; Swift let iconImage = UIImage(named: “icon.png”)! var icon = NSTextAttachment() icon.bounds = CGRect(x: 0, y: (titleFont.capHeight – iconImage.size.height).rounded() / … Read more

uilabel tail truncation

lineBreakMode is a switch. It can be either (for iOS6+) NSLineBreakByWordWrapping or NSLineBreakByTruncatingTail but not both. But, to answer your question, you can find the size of some text using the class extensions in NSString+UIKit. Having found the size you could update the frame of the UILabel appropriately.

UILabel: wrap and/or break inside word(s) with hyphen(s)

Elaborating on Matt’s answer here: https://stackoverflow.com/a/16502598/196358 it can be done using NSAttributedString and NSParagraphStyle. See below: NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.hyphenationFactor = 1.0f; NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:titleString attributes:@{ NSParagraphStyleAttributeName : paragraphStyle }]; self.titleLabel.attributedText = attributedString; This will cause the label to break at logical places mid-word using hyphens. It looks great, … Read more

tech