Questions tagged [uilabel]

The UILabel class implements a read-only text view in iOS. You can use this class to draw one or multiple lines of static text, such as those you might use to identify other parts of your user interface. The base UILabel class provides support for both simple and complex styling of the label text. You can also control over aspects of appearance, such as whether the label uses a shadow or draws with a highlight.

The UILabel class implements a read-only text view. You can use this class to draw one or multiple lines of static text, such as those you might use to identify other parts of your user interface. The base UILabel class provides support for both simple and complex styling of the label text. You can also control over aspects of appearance, such as whether the label uses a shadow or draws with a highlight. If needed, you can customize the appearance of your text further by subclassing.

The default content mode of the UILabel class is UIViewContentModeRedraw. This mode causes the view to redraw its contents every time its bounding rectangle changes. You can change this mode by modifying the inherited contentMode property of the class.

New label objects are configured to disregard user events and clip subviews by default. If you want to handle events in a custom subclass of UILabel, you must explicitly change the value of the userInteractionEnabled property to YES after initializing the object. If you want to allow subviews to extend beyond the bounds of a label, you must explicitly change the value of the label’s clipsToBounds property to NO.

For information about basic view behaviors, see View Programming Guide for iOS.

For more information about appearance and behavior configuration, see Labels in UIKit User Interface Catalog.

6945 questions
2
votes
1 answer

CAGradientLayerHides my UILabel text

I am trying to add gradient background to my labels (which are connected from UserInterface) , but it hides label's text. This is my code so far: //MARK: Grdient label func func gradientBackground(label:UILabel){ let four =…
0ndre_
  • 3,057
  • 5
  • 19
  • 42
2
votes
1 answer

If my UIView is set be opaque, why is it still being colored as "blended" by the simulator?

I have a UILabel that at initialization I set to be opaque (opaque = YES), and if I use the "Debug View Hierarchy" button to preview the views at runtime, I can see that it is indeed set to be opaque as I would expect. However if I turn on Color…
Doug Smith
  • 27,683
  • 54
  • 189
  • 363
2
votes
0 answers

Applying NSFontAttributeName and NSUnderlineStyleAttributeName at the same NSAttributedString

I want to apply NSFontAttributeName as well as NSUnderlineStyleAttributeName to a NSMutableAttributedString. Below is my code but its not working. It only applies the font attribute. If I remove the font attribute, it applies the underline…
kashif789us
  • 404
  • 6
  • 21
2
votes
1 answer

How to edit textlabel created automatically in a new cell after using dequeueReusableCellWithIdentifier

The Cell with Identifier "home" has a textlabel and imageview. I want to edit the content of the label in the newly created prototype cell which are formed after using the function dequeueReusableCellWithIdentifier.
alpha47
  • 305
  • 3
  • 15
2
votes
1 answer

UILabel.text with Singleton String is nil - Warning: Attempt to present ** whose view is not in the window hierarchy

I have a dummy question... in one of my ViewController, I set a UILabel text with a String var coming from a singleton: var nom: String! var prenom: String! override func viewDidLoad() { ..... self.nom = User.sharedInstance.nom self.prenom =…
tiamat
  • 699
  • 1
  • 9
  • 24
2
votes
1 answer

Renaming class causes IBOutlet connection to fail

I renamed a class, which happened to have an outlet connection to a label called mainLabel in a storyboard file. When I run my program, it crashes and gives me the error: "this class is not key value coding-compliant for the key mainLabel". Other SO…
Lahav
  • 711
  • 9
  • 22
2
votes
1 answer

Updating UILabels Off-Screen Causing Them To "Snap" Back

Background Info I am building a tiny stopwatch app. It consists of a main view with a label displaying the time and two buttons: start & stop. The start button activates NSTimers which then call methods that calculate the time passed and then update…
LinusGeffarth
  • 21,607
  • 24
  • 100
  • 152
2
votes
1 answer

UILabel in UICollectionViewCell

I designed UICollectionViewCell in storyboard .Consists 2 elements UILabel, UIImageView. for UILabel i given constrains leading=0, trailing=0, bottom=0, height=100 My collectionViewCell But when i run in simulator: Edit: when i observed in…
UdayM
  • 1,613
  • 11
  • 31
2
votes
2 answers

Size class for UILabel inside UITableView randomly ignored

I have an UITableView with custom cells which contain UILabels. The text size of labels should be different on iPhone and iPad, so I set different fonts for regular size classes in interface builder. The problem is that sometimes on iPad font size…
Szymon
  • 31
  • 4
2
votes
2 answers

UIlabel - link text property with another NSString

Is it possible to "link" UILabel text property with another NSString so that when this other NSString is changed also UILabel text property changes? Example: UILabel *label = [[UILabel alloc] init]; NSString *str = @"labelText1"; label.text =…
troner
  • 229
  • 4
  • 12
2
votes
2 answers

Swift iOS. Multi line UILabel background color to follow the text

I have a multi line UILabel which I want to set the background color exactly the same as when you highlight the text on a web browser with your mouse but cannot seem to find a solution. This is what I got in my storyboard: And this is what I am…
Blake Loizides
  • 965
  • 2
  • 17
  • 43
2
votes
1 answer

Arrange UILabels in UIstackView Dynamically

I am adding labels as subview to UIstackview using arrangedSubView property. what happens is that if I keep Stackview axis horizontal, I get one horizontal strip of UILabels label1 label2 label3 label4..... if I keep it vertical, I get a vertical…
Ranjit
  • 4,566
  • 10
  • 53
  • 118
2
votes
1 answer

Extend UILabel to remove ascender?

In Interface Builder, I'd like to be able to align UILabels by the Cap Height. There's no way to do that in IB, so I thought I might extend UILabel so that the frame starts where Cap Height does (reduce the height of frame by ascender-cap height,…
GoldenJoe
  • 7,100
  • 3
  • 45
  • 79
2
votes
2 answers

Line before and after text in UILabel

I would like to achieve the same result as this : I already saw this : Draw line in UILabel before and after text , but I would like to know if there's a way to do this with only one UILabel ?
Nicolas Charvoz
  • 1,449
  • 12
  • 36
2
votes
2 answers

How to change UILabel width based on text length in iOS Using Auto-Layouts

I want to display two UILabel's, however UILabel's having variable text length's According to textsize UIlabel's width need to increase using auto-layouts. For this I wrote below auto-layouts for both UIlabel's First Label: 1)leading Space 2)Top…
Krish
  • 3,668
  • 10
  • 46
  • 86
1 2 3
99
100