Menu
  • HOME
  • TAGS

Swift : How to set IBOutlet from another controller?

ios,swift,uilabel

The problem you getting is that in viewControllerAtIndex method you trying to set the outlet but the view controller (PageContentViewController) was not loaded to the view hierarchy so the outlet is still nil. One of the solution you can use is add a property to the PageContentViewController for example isHidden...

In a UILabel, is it possible to force a line NOT to break at slash?

ios,uilabel,core-text,hyphenation

An option would be to use a Unicode character rather than normal slash. There are non breaking versions in unicode for space and hyphen. If you were ok to change to using - rather then /, this using @"UI\u2011UX" will show UI-UX and not break the line at the hyhen....

Align two labels vertically with different font size

ios,autolayout,uilabel,vertical-alignment,baseline

Instead of using two different label for rich text you can use AttributedString. Here is a example: - (NSMutableAttributedString*)getRichText { NSString *str1 = @"I am bold "; NSString *str2 = @"I am simple"; NSMutableAttributedString *attString=[[NSMutableAttributedString alloc] initWithString:[str1 stringByAppendingString:str2]]; UIFont *font1=[UIFont fontWithName:@"Helvetica-Bold" size:30.0f]; UIFont *font2=[UIFont fontWithName:@"Helvetica" size:20.0f]; NSInteger l1 = str1.length;...

UILabel not wrapping reliably

ios,swift,uilabel,nslayoutconstraint

The key to getting it to work correctly was to ask the view to reset the layout after the constraints had been applied and all the text had been set. I merely added these lines to my custom UITableViewCell after I had set the data that it needed: //set data...

What's the equivalent of Android's “ClickableSpan” class in Swift/Objective-C?

ios,swift,uilabel,uitextview

You can do that for UITextView by using the dataDetectorTypes property. Objective-C: self.textView.dataDetectorTypes = UIDataDetectorTypeLink; Swift textview.dataDetectorTypes = .Link ...

Cell's accessory keeps truncating UILabel

ios,swift,uitableview,uilabel

You need to set trailing space to the label because bydefault it is taking width that's why its happening . So you need to set it manually.

Why is boundingRectWithSize wrong when using UIFont preferredFontForTextStyle?

ios8,nsstring,uilabel,uifont

A label adds a little margin round the outside of the text, and you have not allowed for that. If, instead, you use a custom UIView exactly the size of the string rect, you will see that the text fits perfectly: Here's the code I used. In the view controller:...

Ambiguous layout warnings for UILabels in UITableViewCell

ios,uitableview,autolayout,uilabel

I solved it by adding for the right UILabel: [self.bodyLabel setContentHuggingPriority: UILayoutPriorityFittingSizeLevel forAxis: UILayoutConstraintAxisHorizontal]; The other thing is that I was testing for ambiguity in updateConstraints, while I should have done it at the end of layoutSubviews...

How can I enforce an UILabel to be wider than it should be, by 5 points?

ios,objective-c,uilabel,uistoryboard,nslayoutconstraint

Finally I solved my problem! It works great like this - Make a subclass of UILabel and override the intrinsicContentSize and sizeThatFits to achieve what you want. So, something like: - (CGSize) intrinsicContentSize { return [self addHorizontalPadding:[super intrinsicContentSize]]; } - (CGSize)sizeThatFits:(CGSize)size { return [self addHorizontalPadding:[super intrinsicContentSize]]; } - (CGSize)addHorizontalPadding:(CGSize)size {...

Custom cell to display multiline label using UITableViewAutomaticDimension

ios,uitableview,swift,autolayout,uilabel

While giving constraints programatically views/controls in content view of UITableViewCell and want to have dynamic cell size based on your text length, you need to give padding from all four sides explicitly(provide some value). Do changes as per below. Looks like a bug In setupLayout method func setupLayout() { let...

How to insert a Cursor into UILable's Text

swift,ios8,cursor,uitextfield,uilabel

UILabel is not UITextField. So you can not do it any other way if you want to add cursor in UILable's Text they you can do it by adding this " | " manually.

How to align custom UINavigationBar title (UILabel )in middle (iOS)

ios,objective-c,uiview,uilabel,uinavigationbar

Add below two lines before addSubview lines.. patientNameLabel.center = CGPointMake(titleView.frame.size.width/2, 0); subTitleLabel.center = CGPointMake(titleView.frame.size.width/2, 25); Add Below Code & see UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,50)]; UIFont * customFont = [UIFont fontWithName:@"Helvetica Neue" size:19]; //custom font NSString * text [email protected]"Nilesh Patel"; UILabel *patientNameLabel; if([text length]>15){ patientNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0,...

Standard text colour by subclassing UILabel for use on a storyboard - (IBOutlet)

ios,objective-c,uilabel,subclass

That's because in init method no UI objects aren't initialised yet. You need to do it in awakeFromNib method. -(void)awakeFromNib { [super awakeFromNib]; [self setTextColor:kColourDefaultAppColourText]; } Or you can use appearance. Set it in eg. didFinishLaunchingWithOptions method with your subclass: [[CHLabel appearance] setTextColor:kColourDefaultAppColourText]; ...

Need to get NSRanges of multiple @ symbols and the text that follows them in UILabel's text

ios,objective-c,uilabel,nsattributedstring,nsrange

One way like this : NSString *strText = @"Hi, my name is John Smith. Here is my twitter handle @johnsmith. Thanks for watching! @somerandomcompany looks good"; //array to store range NSMutableArray *arrRanges = [NSMutableArray array]; //seperate `@` containing strings NSArray *arrFoundText = [strText componentsSeparatedByString:@"@"]; //iterate for(int i=0; i<[arrFoundText count];i++) {...

Pass a Class (UILabel) with its properties through a function Swift

ios,xcode,function,swift,uilabel

Calls to methods (that is, funcs defined within a class or other type) require parameter labels for the second (and subsequent) parameter but not the first. If you want to change which labels are required at the call site, you change the declaration. To require a label on the first...

iOS UILabel view updating has a delay even though console shows output immediately

iphone,swift,ios8,uilabel,synchronous

NSURLSession performs on a background thread, but you should always update UI elements on the main thread. dispatch_async(dispatch_get_main_queue()) { self.attribute1.text = att1Array[0] self.attribute2.text = att2Array[0] self.activityIndicator.stopAnimating() } ...

Center a UIImageView and a UILabel together in a UIView

ios,uiview,uiimageview,uibutton,uilabel

Yes you can. Basically what you need is appropiate constraints. You can add constraints from code or in stoaryboard Code example: NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeCenterX multiplier:1 constant:5]; [view addConstraint:constraint]; NSLayoutConstraint Documentation Auto Layout Tutorial Adaptive Layout Tutorial...

UILabel text updation

ios,ios7,uilabel

NSString *userName =[NSString stringWithFormat:@"%@ %@",self.user.firstName, self.user.lastName]; [[NSUserDefaults standardUserDefaults] setObject:valueToSave forKey:@"preferenceName"]; [[NSUserDefaults standardUserDefaults] synchronize]; save username to NSUserdefaults NSString *userName = [[NSUserDefaults standardUserDefaults] stringForKey:@"preferenceName"]; Take the username whenever you want and assign it to UILabel name whenever the user got Logout clear the NSuserdefaults NSString *userName [email protected]""; [[NSUserDefaults standardUserDefaults]...

Fade the background color of UILabel ? (static display) [duplicate]

ios,objective-c,uiview,uilabel

Do you mean the alpha? If so self.myLabel.backgroundColor = [[UIColor blueColor] colorWithAlphaComponet:0.3];. You can also do this in Attributes Inspector in Storyboard.

UILabel set framework doesn't work if the value is negative

ios,objective-c,uiscrollview,uilabel,frame

The problem is that the label changes the position at the same time and speed with the scroll so it is normal for it to appear as it doesn't move at all.

Swift: How can you rotate text for UIButton and UILabel?

ios,swift,uibutton,uilabel

I am putting my answer in a similar format to this answer. Here is the original label: Rotate 90 degrees clockwise: yourLabelName.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2)) Rotate 180 degrees: yourLabelName.transform = CGAffineTransformMakeRotation(CGFloat(M_PI)) Rotate 90 degrees counterclockwise: yourLabelName.transform = CGAffineTransformMakeRotation(CGFloat(-M_PI_2)) Do the same thing to rotate a button. Thankfully the touch events also...

How do I toggle hidden of a label while a button is pressed?

ios,uibutton,uikit,uilabel

The UIButton class, as well as lots of other UIControl subclasses can have numerous actions hooked up to them. When we are hooking up an action from interface builder to our source code file, if we open the "Event" drop down, we're presented with a long list of options: In...

How to redefine “word” in NSLineBreakByWordWrapping

ios,objective-c,uilabel

To achieve this you can replace the spaces in your UILabel for non-breaking space. For example: label.text = @"Hello,\u00a0world!"; ...

How to pass label data to another label in the second view controller

objective-c,uilabel,pushviewcontroller

1. Save the strings content in the first implementation file and load it in the second Save your label.text in first class: [[NSUserDefaults standardUserDefaults] setObject:Label.text forKey:@"Your key"]; Load it in the second class: Label.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"Your key"]; 2. Use parameters In the first class you have to implement...

shadow in UILabel

ios,objective-c,uilabel

self.layer.shadowOffset = CGSizeMake(0, -2.5); self.layer.shadowRadius = 1; self.layer.shadowOpacity = 0.5; self.layer.shadowColor = [UIColor blackColor].CGColor; ...

Auto size UILabel text

ios,objective-c,uilabel

I have a UILabel with multi lines Well, that's the problem. The automatic size adjustment feature of UILabel works only for 1-line UILabels (i.e. numberOfLines must be 1). You might be happier with two labels, one being a single-line UILabel for the first line which can shrink its size,...

Adjusting font size for UILabel according to device screen iPhone4/5 and iPhone6/Plus

ios,objective-c,iphone,fonts,uilabel

adjustsFontSizeToFitWidth only scales the font down, not up. So, if you want a bigger font you need to set one, either specifically for the iPhone 6 or always and allow iOS to scale the font down for the iPhone 4 / 5.

Display json response in to UILabel

ios,json,uilabel

NSNumber * num = [[jsonDisplay objectAtIndex:0]valueForKey:@"no_of_files"]; viewController.numberofFiles.text = [num stringValue]; ...

How to wrap a text on a UIButton in swift

ios,swift,uibutton,uilabel

You need to write text in the setTitle method: nextButton.setTitle("This is the very very long text!", forState: UIControlState.Normal) Set the number of lines and wrap mode to the title label: nextButton.titleLabel.numberOfLines = 0; // Dynamic number of lines nextButton.titleLabel.lineBreakMode = NSLineBreakByWordWrapping; ...

What to do if label is bigger than parent UIVIew?

ios,autolayout,uilabel

I believe rounding occurs somewhere in iOS because the label would fit (one line and then at the end with ...) if there would be 0.75pt more space. So it draws it but it is cut off because of the missing 0.75pt space. Now I took the following approach: Calculate...

AutoLayout constraints to UITableViewCell contentView not respected

ios,uitableview,autolayout,uilabel

The paddings is layout margins. You have to be beware of Constrain to margins option. Constrain to margins is Enabled: Constrain to margins is Disabled: How to disable it? You can double-click the one of constrains and unchecking the Relative to margin option: Unchecking the Constrain to margins while creating...

iOS gradient effect over UILabel

ios,objective-c,iphone,uilabel

You code is correct but you miss setting the frame that will be occupied by the CAGradientLayer.. And take note that you need to use color with alpha value, to avoid occurrence of black color.. ex: [UIColor colorWithRed:0 green:0.5 blue:1 alpha:0] or [[UIColor YourColor] colorWithAlphaComponent:0] instead of [UIColor clearColor] And...

How to blur UILabel text [closed]

ios,uilabel

You can just create a subclass of UILabel that creates the blur effect. Here is a boiler template: BlurredUILabel.h #import <UIKit/UIKit.h> @interface BlurredUILabel : UILabel @property (nonatomic, readwrite) IBInspectable CGFloat blurRadius; @end BlurredUILabel.m #import "BlurredUILabel.h" @implementation BlurredUILabel - (void)setText:(NSString *)text { super.text = text; UIGraphicsBeginImageContext(self.bounds.size); [self.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image =...

fatal error when prepared to segue to view controller

xcode,swift,uilabel,segue

First Of all Update your code in your ViewController like this: class ViewController: UIViewController { @IBAction func action(sender: AnyObject) { let alertController: UIAlertController = UIAlertController (title: "Next Page", message: "", preferredStyle: .Alert) let yesAction = UIAlertAction (title: "YES", style: .Default ) { action -> Void in self.performSegueWithIdentifier("test", sender: self) }...

TTTAttributedLabel sizetofit and sizeWithFont is different

ios,uilabel,sizetofit,sizewithfont,tttattributedlabel

You should calculate sizing instead with TTTAttributedLabel's built-in method +[TTTAttributedLabel sizeThatFitsAttributedString: withConstraints:limitedToNumberOfLines:, which will return a proper CGSize for you....

Multiple UILabel not displaying with UIView loaded from nib

ios,objective-c,uiview,uilabel

You should create this as the header view in your layout and then set the content offset / inset to have it initially scroll off screen if that's your aim. By making it part of the layout it will be correctly managed, whereas by adding it directly to the collection...

Subview of UILabel disappears when the text was changed to Unicode string

ios,uilabel,subview,unicode-string

UILabel is not intended to have subviews. The solution is to make your blue rectangle a subview of your label's superview. You can position it so that it appears in front of your UILabel. Thus, where you have this code: UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)]; [view...

Clickable username and hashtag in UILabel (Not UIWebView!)

ios,objective-c,swift,uilabel,clickable

Using a method will force you to make two of them (User 1 and User 2) and align it every time you draw it. I think it's better to make a category ( or Swift extension) of UILabel that gets it's frame and add a gesture recognizer with that frame...

Vertically center UILabel in parent UIView

ios,iphone,xcode,uiview,uilabel

CGPoint center = self.label.center; center.y = view.frame.size.height / 2; [self.label setCenter:center]; ...

swipe gesture strike through text [closed]

objective-c,xcode,uilabel,uiswipegesturerecognizer,swipe-gesture

You could try a simple gesture recogniser like this.. Add the following in your viewDidLoad or similar UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(strikeThrough)]; swipe.direction = UISwipeGestureRecognizerDirectionRight; [self.nameTextField addGestureRecognizer:swipe]; Then setup the strikeThrough method to change the text to strikethrough - if you only have one textfield just add a...

How to animate an UILabel from small to its original size?

ios,objective-c,uilabel,uianimation

Put this in viewDidAppear -(void)viewDidAppear:(BOOL)animated{ self.label.transform = CGAffineTransformMakeScale(0.01, 0.01); [UIView animateWithDuration:0.5 animations:^{ self.label.transform = CGAffineTransformIdentity; } completion:^(BOOL finished) { }]; } ...

How can I centre both vertically and horizontally in a UILabel after resizing the text to fit width (1 line label)?

ios,objective-c,uitableview,uilabel

You are setting the label as a one-line label (by default) and setting its height at a fixed height, thus fixing its position: UILabel *numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 0, 60, 40)]; Thus, you are getting a constant baseline position for all your labels, regardless of the font size. So...

How to change UILabel text color on Custom UITable cell?

objective-c,uilabel,tableviewcell,swrevealviewcontroller,viewwithtag

If you have multiple labels in cell, then you need to set its color separately To get cell which is loaded in memory, use UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; remove if(indexPath.row == 0) condition to apply color on every cell. and loop in cell.contentView for labels (If multiple label, You...

Center multiple UILabels on a line

ios,swift,view,uilabel,center

Here is a snapshot of a working set of all the constraints on an abbreviated layout that produces an always-centered view that automatically resizes with the child views (i.e., as the content of any label changes, the view grows or shrinks around it). Important to your solution, the view has...

Set different font styles for WKInterfaceLabel with multiple lines

swift,uilabel,watchkit,wkinterfacelabel

The easiest way to do this would be to create two labels in your storyboard, each with their own font style. Then, use setText to set the first and second lines. Unfortunately, WKInterfaceLabel doesn't provide any typesetting metrics, so there's no built-in method to determine where a line-break occurs. If...

UILabel Swift/Storyboard returns nil

swift,uilabel

Instead of this, the correct way is to set a property of your emergencyViewController. In your emergencyViewController viewDidLoad set your label text according to the property set previously. Anything that you do between initialize of a viewController to viewDidLoad will not take effect....

Wrap Text in UITableView Custom Cell When It Reaches End of Screen (Swift)

ios,uitableview,swift,uilabel

Set label number of "Lines" to ZERO. And set "Line Breaks" to "Word Wrap"

cell.textLabel.text not working after update to Xcode 6.2 using swift

ios,objective-c,xcode,swift,uilabel

Put a ? after textLabel; Xcode expects an Optional here. Not sure what in the update would have changed that, but if I take the ? out of my similar code thats same error I see. I believe that Xcode automatically suggested the ? in the previous version.

Displaying a string with multiple attributes in a label

ios,nsstring,uilabel,nsattributedstring

NSMutableAttributedString *str = [[NSMutableAttributedString alloc] init]; [str appendAttributedString:[[NSAttributedString alloc] initWithString:@"Will change in " attributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:17], NSForegroundColorAttributeName : [UIColor whiteColor] }]]; [str appendAttributedString:[[NSAttributedString alloc] initWithString:@"10 sec" attributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:19], NSForegroundColorAttributeName : [UIColor yellowColor] }]]; myLabel.attributedText = str; ...

Change date in UILabel when click next and previous UIButton

ios,objective-c,uilabel,nsdate,updates

Check this - (void)viewDidLoad { [super viewDidLoad]; NSDateComponents* deltaComps = [[NSDateComponents alloc] init] ; NSDate* tomorrow = [[NSCalendar currentCalendar] dateByAddingComponents:deltaComps toDate:[NSDate date] options:0]; NSDateFormatter *myDateFormatter = [[NSDateFormatter alloc] init]; [myDateFormatter setDateFormat:@"dd-MM-yyyy"]; NSString *stringFromDate = [myDateFormatter stringFromDate:tomorrow]; dateLabel.text = stringFromDate; // Do any additional setup after loading the view. } -...

Get the vertical Size of a UILabel which has more than one line?

ios,swift,uilabel

You don't need to calculate the height, the label knows its height after it has laid itself out, override func viewDidLoad() { super.viewDidLoad() println(label.frame.height) // 21 label.text = "Some long text to make the text go over more than one line" label.layoutIfNeeded() println(label.frame.height) // 101.5 } ...

What's the difference between var label: UILabel! and var label = UILabel( )?

ios,swift,uilabel

var label: UILabel! is declaring that you have a UILabel variable that may be empty (Optional), but you can access it pretending as if it will not - usually that means it would be an IBOutlet that would be set by the interface storyboard on load, before you tried to...

Detect number of touches

ios,uilabel,uigesturerecognizer,touchesbegan

You're talking about changing state after a touch. Most people would use just a boolean, or an integer enum to keep track of what state they're in, and fork the code accordingly. However, if you need to discern between a tap, a double tap, a triple tap, a pan, or...

Is there a way to use a UIButton for text in a countdown timer?

ios,objective-c,timer,uibutton,uilabel

You want to use a button to present count down? I think you can use the way below. I tried it and it works for me. I have three properties @property(nonatomic,assign)NSInteger time; @property (weak, nonatomic) IBOutlet UIButton *smsButton; @property(nonatomic,strong)NSTimer *timer; And then start the timer with a method: - (void)smsButtonPressed...

Implement some insets in HTMLLabel but “drawTextinRect” get never called

ios,objective-c,uilabel,uiedgeinsets

My guess is that it's because what this class is doing is illegal. For example, it overrides drawRect:, which you are not allowed to do for a UILabel. Moreover, it does this without calling super. So it has interfered with the normal workings of the underlying UILabel, and you are...

How to add background line in multiline label using NSAttributedString in ios objective-c

ios,objective-c,uilabel,cashapelayer

You may mean Strike,iOS 6.0 and upper , UILabel supports NSAttributedString and NSMutableAttributedString When use NSAttributedString NSAttributedString * title = [[NSAttributedString alloc] initWithString:@"Your String here" attributes:@{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle)}]; [label setAttributedText:title]; Definition : /** * Returns an NSAttributedString object initialized with a given string and attributes. * * @param str : The string...

Adjusting UILabel size and text position after calling sizeToFit

ios,objective-c,uilabel

I would do this by creating a subclass of UILabel, and overriding intrinsicContentSize instead of drawTextInRect:. override func intrinsicContentSize() -> CGSize { self.sizeToFit() frame = frame.rectByInsetting(dx: -12, dy: -6) var size = frame.size return size } Of course, the text alignment also needs to be set to centered....

UIView Animation not shown after segue

swift,uiview,uicollectionview,uilabel,uiviewanimation

Move your Animation block into viewDidAppear()

lineBreakMode for multiline attributed string

ios,uilabel,nsattributedstring

The solution that i adopted is while (newHeight>=heightOfLabel){ remove some letter from the end of the string calculate new height } replace the last three charachter with "..." and it is done :) I know that it is not a clean solution but it resolve my issue until finding a...

How to know the width of last line of label?

ios,iphone,swift,uilabel

Set the text of the UILabel Get the width of this UILabel with yourUILabel.frame.width Set the x coordinate of your UIImage at yourUILabel.frame.width + emptySpace like this var yourUIImageView:UIImageView = UIImageView(frame: CGRectMake(x:PaddingFromLeft + yourUILabel.frame.width + emptySpace, y: yourYCoordinate, width: yourImageWidth, height : yourImageHeight)) ...

iOS7 - Adjusting font size of multiline label to fit its frame

ios,fonts,uilabel,font-size

You also need to check every words to be sure they aren't being truncated, since boundingRectWithSize: will never return a CGRect wider than the width you provided (even if a single word doesn't fit in the width). Here is a similar loop with that mechanic in place: - (void)setButtonTitle:(NSString *)title...

How to format some text as bold within a UILabel? [duplicate]

ios,uilabel

Use the attributedText property: NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"This is a test."]; [text addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:12] range:NSMakeRange(0, 4)]; label.attributedText = text; ...

Animation of setAlpha for UILabel not working

ios,objective-c,animation,uilabel,alpha

Quick fix: Use an animateWithDuration method instead of transitionWithView for alpha transitions.

Create a label with close button

ios,uilabel

You need to create a custom UIView and use touch at specific location to dismiss that uiview which i think acts similar to close button in functionality. and to remove that view use the following code to recognize the touch on the custom view in touches began method: CGPoint locationPoint...

How to change Custom Cell's UILabel Text?

ios,objective-c,uitableview,uiview,uilabel

You need to make a class that is a subclass of UITableViewCell, and set the custom cell's class to the class you made. Then you want to link the labels using IBOutlets in the cell to the subclass you made. Finally, in -tableView:cellForRowAtIndexPath:, you should cast the cell to your...

Vertically align text within a UILabel (xcode)

ios,iphone,xcode,swift,uilabel

ok. do the following: drag LEFT from the label to the view, release and choose Leading Space to Container Margin drag RIGHT from the label to the view, release and choose Trailing Space to Container Margin drag UPWARDS from the label to the view, release and choose Top Space to...

How do I handle long text labels on a universal storyboard?

ios,xcode,swift,uilabel

Here is a simple gif, which can help you to understand it better. ...

How can I animate the size of UILabel or UITextField text?

ios,objective-c,uilabel,core-animation

You don't have to capture the image from the view, you can simply use scale transform on your label using the following code [UIView beginAnimations:nil context:nil]; label.transform = CGAffineTransformMakeScale(3.0, 3.0); [UIView commitAnimations]; But the only problem with this approach is that the text might not appear crisp. If you want...

Updating width of uilabel when subview not

ios,uitableview,autolayout,uilabel

When you hide a view, it still takes part in the layout process. So simply hiding your UISwitch will not cause anything to change. So you either have to add/remove constraints, remove the UISwitch from its containing view or change how you are doing the constraints. Option 1: Instead of...

How can I set a special character(right arrow) in UILabel?

xcode,uilabel

Try using unicode: mylabel.text = @"\u25BA section 1"; ...

Object properties to UILabel

ios,objective-c,object,uilabel

You may use the code like that: id object; // your object NSArray *properties = @[ @"prop1", @"prop2", ... ]; // your properties [properties enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, idx * 30, 0, 30)]; // or set your custom frame label.text =...

Indent second line of UILabel

ios,objective-c,uilabel

Use an NSAttributedString for your label, and set the headIndent of its paragraph style: NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; style.headIndent = 14; NSDictionary *attributes = @{ NSParagraphStyleAttributeName: style }; NSAttributedString *richText = [[NSAttributedString alloc] initWithString:@"So this UILabel walks into a bar…" attributes:attributes]; self.narrowLabel.attributedText = richText; self.wideLabel.attributedText = richText; Result:...

UILabel Not Updating After Segue

ios,objective-c,xcode,uilabel

I guess initWithCoder: is not called. It is recommended to set data you want in viewDidLoad. - (void)viewDidLoad { [super viewDidLoad]; self.nameLabel.text = @"NAME"; self.addressLabel.text = @"ADDRESS"; } If not solved, check the views state, such as frame, hidden or alpha value. - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; NSLog(@"[nameLabel] frame :...

How to update UI with WatchKit?

ios,uibutton,uilabel,watchkit

To update a WKInterfaceLabel's text property you need to use setText(): self.myLabel.setText("new text") ...

iOS swift multi-line UILabel in a view

ios,uiview,autolayout,uilabel,multiline

Either your multi-line label, or the outer view needs to have its width constrained in some way, otherwise the label will expand its width to whatever it needs to accommodate the text on one line. If that line is long enough, the text will run off the edge of the...

UILabel returns “nil”?

swift,uibutton,uilabel,nil,ibaction

It would help if you clarified how you want it to behave. If you're wondering why it's an optional and why it's returning nil then you can fix this as follows. In your checkButton() function you have this line at the end: currentCountLabel.text = "\(currentCount)" Unwrap the currentCount variable to...

how to make a specific fragment of an NSAttributedString a specific color in Swift

swift,uikit,uilabel

You already have this: let blueFont = UIFont(name: "HelveticaNeue-BoldItalic", size:14.0) myMutableString.addAttribute( NSFontAttributeName, value: blueFont!, range: myItalicizedRangeBlue) And this: let blueAttrs = [NSForegroundColorAttributeName : UIColor.blueColor()] So now just add another attribute: myMutableString.addAttributes( blueAttrs, range: myItalicizedRangeBlue) // or any desired range Or, combine the attributes first and add them together, if they...

bug with LineBreakMode

ios,objective-c,uilabel,nsparagraphstyle

YES! ;) I get this line in format: \U041f\U0438\U0440\U043e\U0436\U043d\U044b\U0435\U00a0Laduree\U00a0\U00ab\U043e\U0434\U0435\U0442\U044b\U0435\U00bb \U0432\U00a0Emilio Pucci where \U00a0 is wrong spaces (NO-BREAK SPACE), i encode this line and replace wrong spaces to normal spaces...

It is possible to continuously update the UILabel text as user enter value in UITextField in iOS

ios,objective-c,swift,uitextfield,uilabel

You can register your textField for value change event: [textField addTarget: self action:@selector(textFieldDidChange) forControlEvents:UIControlEventEditingChanged]; and in textFieldDidChange function update your label: - (void)textFieldDidChange { label.text = textField.text; } The function shouldChangeCharactersInRange is needed more for taking desisions whether to allow upcoming change or not...

Change text of label in ios camera overlay UIPickercontroller

ios,objective-c,xcode,uilabel,uipickerviewcontroller

Just Pass the Label As a whole to the Timer Function: Say Your Label is defined in ViewDidLoad like this : - (void)viewDidLoad { //Do Something here UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(xcoordinateLabel, ycoordinateLabel, width, height)]; label.backgroundColor = [UIColor clearColor]; label.textAlignment = UITextAlignmentCenter; label.textColor=[UIColor whiteColor]; label.text = @"TEST"; [self.view...

UILabel does not wrap on initial load within TableViewCell

ios,swift,uilabel,tableviewcell

The issue is likely to be that the frame width you are using is wrong. Cells created using deqeueReusableCellWithIdentifier have no size class associated with them because they have no parent view. Hence if you have constraints in your cell, trying to calculate layout sizes manually does not work properly....

How to get monospaced numbers in UILabel on iOS 9

ios,uilabel,uifont,monospace,ios9

What about: let originalFont = UIFont.systemFontOfSize(17) let originalFontDescriptor = originalFont.fontDescriptor() let fontDescriptorFeatureSettings = [ [ UIFontFeatureTypeIdentifierKey: kNumberSpacingType, UIFontFeatureSelectorIdentifierKey: kMonospacedNumbersSelector ] ] let fontDescriptorAttributes = [UIFontDescriptorFeatureSettingsAttribute: fontDescriptorFeatureSettings] let fontDescriptor = originalFontDescriptor.fontDescriptorByAddingAttributes(fontDescriptorAttributes) let font = UIFont(descriptor: fontDescriptor,...

Swift - UILabel from URL

ios,swift,uilabel,nsurl

If you don't want to use sessions, you can also use the simpler NSURLConnection Class, something like this: let url = NSURL(string: "https://wordpress.org/plugins/about/readme.txt") let request = NSURLRequest(URL: url!) NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) {(response, data, error) in println(NSString(data: data, encoding: NSUTF8StringEncoding)) dispatch_async(dispatch_get_main_queue()) { // Do stuff on the UI thread self.textField.text =...

Change paragraph height (not line spacing) in a UILabel

ios,uilabel,nsattributedstring

One thing I didn't mention in the question, which I had thought was obvious from the example is that the description is not within my control, it is generated by users. Therefore, the carriage return characters are added by them when they are creating the text. So the solution I...

MVC communication, update label from model class in Swift

ios,swift,oop,model-view-controller,uilabel

Your error is here var callV = ViewController().label You are creating a new instance of ViewController,you should get the reference of the existing one You can pass in a label as input func changeLabel(label:UILabel){ var elementCall = callElements() println("111") label.text = elementCall } Then call modelFrom.callElements(self.label) Update: I suggest you...

iOS: How to Detect subview position around view

ios,objective-c,uiview,uilabel,uitouch

I believe you want to use this method: [self.view convertRect:self.label.frame fromView:self.view.subview]; from this post: How to get the frame of a view inside another view? This will give you the adjusted position of the label form your list of 1000+ labels. You can then compare that to the label of...

Can't set UILabel Text Programmatically

ios,objective-c,uilabel

Diagnosing this offline, we confirmed that this was really being received on a background thread. In that case, you can either post the notification to the main queue, or you can have updateProgressDialog dispatch the UI updates to the main queue: -(void) updateProgressDialog: (NSNotification *) notification{ NSString *message = [notification...

UILabel cutting off text

objective-c,xcode,uilabel

As mentioned, unless you use a monospaced font, 12 characters are going o occupy a varying amount of space. The easiest thing to do in this case is to set the adjustsFontSizeToFitWidth to YES. This will scale the text so that it fits the width of its container....

Which UILabel method is invoked when I set text, and it resizes itself to fit?

ios,storyboard,uilabel,nslayoutconstraint

Unfortunately, we don't have any contentEdgeInsets property we can set on a UILabel (as we do have on a UIButton). If you want auto layout to continue to make the height and width constraints itself, you could make a subclass of UILabel and override the intrinsicContentSize and sizeThatFits to achieve...

Swift: Problems printing out UILabel.text

ios,swift,uilabel

You can set the string to a variable, and then print that. So: var latitudeString : String = self.latitude.text println(latitudeString) Edit: Seems like casting the latitude as a String is not properly happening. What you could do is the following: var lat : Float = firstObject["LAT"] as! Float var latString...

Assigning Text to Labels Dynamically

ios,objective-c,uilabel

Why not consider NSUserDefaults? It can even pass the data across sessions. Pass the data: - (IBAction)saveLabel:(id)sender { NSArray *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"DATA"]; NSMutableArray *currentDataArray; if (data == nil) { currentDataArray = [[NSMutableArray alloc]init]; } else { currentDataArray = [[NSMutableArray alloc]initWithArray:data]; } [currentDataArray addObject:self.textField.text]; [[NSUserDefaults standardUserDefaults] setObject:currentDataArray forKey:@"DATA"]; }...

UILabel word wrapping

ios,objective-c,uilabel,wrap,word

You are missing some information, so this is basically a very educated guess: I assume you are using Autolayout for this (probably should have tagged it). The behavior you see can be caused if you have set preferredMaxLayoutWidth of the label to a higher value than what is actually used....

Change first line color of UILabel

ios,objective-c,uilabel,nsattributedstring

The problem is here [text addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:[label.text rangeOfString:@"\n"]]; It will color only \n You need range from 0 to start of \n Edit : You can try this code (it's not tested but should work) NSRange rangeOfNewLine = [label.text rangeOfString:@"\n"]; NSRange newRange = NSMakeRange(0, rangeOfNewLine.location); [text addAttribute:NSForegroundColorAttributeName value:[UIColor...

Reload UIViewController in “viewDidLoad”

ios,objective-c,uilabel,viewdidload

A very stupid bug. Turns out when I made the segue to transition into the next view, I actually dragged it from a physical cell on to the destination controller. However, I should've simply connected the sending uiview controller to the destination viewcontroller with the segue, and then manually handled...