【iOS Development】UILabel

foreword

Recently, I started to learn about UI for iOS development. The learning process started from ULable. The author wrote notes step by step to record his learning process.

1. The concept of UILable

Our UILable is aA view that can be displayed on the screen and can display text, the text on our qq or the circle of friends on wechat are actually a kind of UILabel

2. The properties of UILable

Our UILable, like any of our objects, needs to be created through alloc and init
insert image description here

Attribute 1: text

The text property of UILabel is a string object, so we must also assign a string object when assigning a value
insert image description here

Attribute 2: frame

Frame means frame
Because the parent class of our UILable is our UIView, all UIViews including UIView subclasses have this property
insert image description here

Attribute 3: backgroundColor

insert image description here
Through the code, we can see that the background color we can set is not only our lable object, but also the background color of our original interface

Attribute 4: font

We can also set our font size
insert image description here

Attribute 5: textColor

insert image description here

advanced properties

insert image description here
It is more important to note here that ournumberOfLinesAttribute, we generally set it to 0 to automatically adjust the number of lines of our text.
At the same time, we use textAlignment to set the alignment position of our text box. Alignment means alignment

We must pay attention here that we must add the subview we created to our parent view, otherwise the view we created will not be displayed
insert image description here

Finally, it must be noted that we need to call the function we created in our viewDidLoad method to display our view, otherwise it cannot be displayed
insert image description here

Here is our final rendering
insert image description here

Guess you like

Origin blog.csdn.net/weixin_72437555/article/details/130630717