Display HTML text in UILabel iphone

You can do it without any third-party libraries by using attributed text. I believe it does accept HTML fragments, like the one you’re getting, but you may want to wrap it in a complete HTML document so that you can specify CSS: static NSString *html = @”<html>” ” <head>” ” <style type=”text/css”>” ” body { … Read more

iOS AutoLayout multi-line UILabel

There’s an answer this question on objc.io in the “Intrinsic Content Size of Multi-Line Text” section of Advanced Auto Layout Toolbox. Here’s the relevant info: The intrinsic content size of UILabel and NSTextField is ambiguous for multi-line text. The height of the text depends on the width of the lines, which is yet to be … Read more

sizeWithFont method is deprecated. boundingRectWithSize returns an unexpected value

How about create new label and using sizeThatFit:(CGSize)size ?? UILabel *gettingSizeLabel = [[UILabel alloc] init]; gettingSizeLabel.font = [UIFont fontWithName:@”YOUR FONT’s NAME” size:16]; gettingSizeLabel.text = @”YOUR LABEL’s TEXT”; gettingSizeLabel.numberOfLines = 0; gettingSizeLabel.lineBreakMode = NSLineBreakByWordWrapping; CGSize maximumLabelSize = CGSizeMake(310, CGFLOAT_MAX); CGSize expectSize = [gettingSizeLabel sizeThatFits:maximumLabelSize]; Edit: This upper code is not good for ios 7 and above, … Read more

Multiline label in UIStackView

The correct answer is here: https://stackoverflow.com/a/43110590/566360 Embed the UILabel inside a UIView (Editor -> Embed In -> View) Use constraints to fit the UILabel to the UIView (for example, trailing space, top space, and leading space to superview constraints) The UIStackView will stretch out the UIView to fit properly, and the UIView will constrain the … Read more

Xcode – update ViewController label text from different view

You have to implement protocols for that. Follow this: 1) In SettingView.h define protocol like this @protocol ViewControllerDelegate -(void) updateLabel; @end 2) Define property in .h class and synthesis in .m class.. @property (nonatomic, retain) id <ViewControllerDelegate> viewControllerDelegate; 3) In SettingsView.m IBAction -(IBAction)backToMain:(id) sender { [viewControllerDelegate updateLabel]; } 4) In ViewController.h adopt protocol like this … Read more

UILabel visible part of text

You could use a category to extend NSString and create the method you mention @interface NSString (visibleText) – (NSString*)stringVisibleInRect:(CGRect)rect withFont:(UIFont*)font; @end @implementation NSString (visibleText) – (NSString*)stringVisibleInRect:(CGRect)rect withFont:(UIFont*)font { NSString *visibleString = @””; for (int i = 1; i <= self.length; i++) { NSString *testString = [self substringToIndex:i]; CGSize stringSize = [testString sizeWithFont:font]; if (stringSize.height > … Read more

How to create an image from UILabel?

From: pulling an UIImage from a UITextView or UILabel gives white image. // iOS – (UIImage *)grabImage { // Create a “canvas” (image context) to draw in. UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, 0.0); // high res // Make the CALayer to draw in our “canvas”. [[self layer] renderInContext: UIGraphicsGetCurrentContext()]; // Fetch an UIImage of our “canvas”. UIImage *image … Read more