In earlier versions of xcode, empty templates are selected during exercises, and. the didfinishlaunchingwitexceptions in M writes code to instantiate the control object (such as tag), and then uses [self. window addsubview: object] is displayed.
However, in the latest versions of xcode, there is no empty template option, but a single MVC template. write code in viewdidload of M and use [self. view addsubview: label1] to display the control.
The following are the attributes of the label:
-(Void) viewdidload {// initialize a label1 tag object. There are many initialization methods. The most primitive method is init, here we use the method uilabel * label1 = [[uilabel alloc] initwithframe: cgrectmake (30, 30,300, 30)]; // set the content [email protected] "label 123 Hello world. How are you? At home? "; // Set the text color label1.textcolor = [uicolor whitecolor]; // set the label background. clearcolor indicates the transparent background. label1.backgroundcolor = [uicolor redcolor]; // set the text aligment label1.textalignment = nstextalignmentcenter; // set the font. The uifont class has many ways to set the font. You can click cmd + to view the font. Label1.font = [uifont boldsystemfontofsize: 23]; // This font will overwrite the above settings, but whether the word is skewed or not needs to be bold depends on the specific font label1.font = [uifont italicsystemfontofsize: 23]; // print out all system fonts, which is also a method in uifont. You can click cmd + to view nsarray * arr1 = [uifont familynames]; for (nsstring * Name in arr1) {nslog (@ "% @", name) ;}// the method for modifying the font and font size at the same time label1.font = [uifont fontwithname: @ "Georgia" Size: 40]; // sets the shadow color label1.shadowcolor = [uicolor blackcolor]; // sets the shadow offset value, which must be cgsizema. Ke VALUE. The first value indicates the offset between the left and right,> 0 to the right, and the second value indicates the upper and lower offset.> 0 label1.shadowoffset = cgsizemake (2, 5). // you can specify a highlighted value, if it is set to yes, the highlighted color below replaces the original textcolor. If it is set to no or the highlighted color is not enabled, the highlighted color setting is invalid, still display the textcolor value label1.highlighted = yes; label1.highlightedtextcolor = [uicolor redcolor]; // automatically adjust the text size according to the label size. If it is not enabled, the extra text will be used... indicates label1.adjustsfontsizetofitwidth = yes; // The text and label are aligned with the label midline at the top, middle, and bottom of the text. You can click cmd + Any of the following values to find that this is an enumeration. The default value is always // The following method is valid only when there is only one line of text label1.baselineadjustment = plaintext; label1.baselineadjustment = plaintext; uilabel * label2 = [[uilabel alloc] initwithframe: cgrectmake (30, 80,300, 80)]; [email protected] "Hello World"; // when there are many texts, or display 1 line... omit // set the number of rows to be displayed. 0 indicates no limit on the number of rows. However, because the label height is fixed, if the number cannot be displayed... label2.numberoflines = 0 is omitted; // set the line feed and last truncation/omitting // nslinebreakbywordwrapping-line feed in the unit of words, truncated in the unit of words (that is, no ..., if it cannot be displayed, it will not be displayed.) by default, CMD + Click discovery is also an enumeration // nslinebreakbycharwrapping-line feed in character units, truncation in characters // nslinebreakbyclipping-line feed in words, Truncation in characters // nslinebreakbytruncatinghead-line feed in units, Truncation in characters, but before the last line is... omitted. If it is a row, there will be... // nslinebreakbytruncatingtail-line feed in units, truncated in characters, but at the end of the last line is... omitted. If it is a row, there will be... // nslinebreakbytruncatingmiddle-line breaks in units and truncates characters, but the middle of the last line is... omitted. If it is a row, there will be... label2.linebreakmode = nslinebreakbytruncatinghead; // adjust the Label Size Based on the content. The trilogy uilabel * label3 = [[uilabel alloc] initwithframe: cgrectzero]; [email protected] "tag 3 tag 3 tag 3 tag 3 tag 3 tag 3 tag 3 tag 3 tag 3 tag 3 tag 3 tag 3 tag 3 tag 3 tag 3 tag 3 "; // 1. The size of the calculated content, that is, the obtained height and width. In fact, the width is generally given, but the calculation height. The two-dimensional object of the height and width is generally a cgsize size1 = [label3.text sizewithfont: label3.font constrainedtosize: cgsizemake (300,100 0) linebreakmode: nslinebreakbycharwrapping]; // 2. Set the number of lines displayed, that is, the function label3.numberoflines is not limited to 0; // 3. Use size1 to set the label width and height label3.frame = cgrectmake (30,180, size1.width, size1.height ); // Add the previously initialized labels label1, 2, and 3 to the current view and display them together with [self. view addsubview: label1]; [self. view addsubview: label2]; [self. view addsubview: label3]; [Super viewdidload]; // do any additional setup after loading the view, typically from a nib .}
Uilabel class usage and various attributes of instantiated objects