In iOS, use [Uifont Familynames] This method to obtain 72 kinds of system fonts.
Use the [Uifont fontwithname:@ Zapfino size:18] method to set the font and font size for text in space.
You can use a For loop to bulk define a control and set properties.
The following programs get the system 72 fonts and store them in an array, either by getting each font in a for loop and adding it to a mutable array, or by assigning 72 fonts directly to an array.
Note: In the case of fewer page controls, choose to create each control manually, using a looping batch to create the control when the number of controls is large and regular. The size of the control can be automatically fitted to the device by acquiring the resolution of the hardware device. The specific way is:
Screen size
CGRect rect = [[UIScreen mainscreen] bounds];
Cgsize size = rect.size;
CGFloat width = size.width;
CGFloat height = size.height;
NSLog (@ "Print%f,%f", width,height);
Resolution
CGFloat Scale_screen = [UIScreen mainscreen].scale;
Width*scale_screen,height*scale_screen
Program content:
#import "ViewController.h" @interface Viewcontroller () @end @implementation Viewcontroller-(void) Viewdidload {[
Super Viewdidload];
Defines a variable array that holds all fonts nsmutablearray *fontarray = [Nsmutablearray arraywithcapacity:10];
Traversal UI font for (ID x in [uifont Familynames]) {NSLog (@ "%@", X);
[Fontarray addobject:x];
///directly store the fonts in the array nsarray *fontarrauy2 = [Uifont familynames];
NSLog (@ "%@", fontarrauy2);
Creates a label that displays the string Uilabel *mylab1 = [[Uilabel alloc]initwithframe:cgrectmake (100, 100, 200, 50)];
Mylab1.font = [Uifont systemfontofsize:20];
Mylab1.font = [Uifont fontwithname:@ "Zapfino" size:18];
Mylab1.font = [Uifont fontwithname:[fontarray objectatindex:10] size:18];
Mylab1.text = @ "HelloWorld";
[Self.view ADDSUBVIEW:MYLAB1];
Creates a new variable array that holds the label nsmutablearray *labarr = [Nsmutablearray arraywithcapacity:100] that is created using the For loop in bulk; for (int x=0; x<24; x + +) {for (int y=0; y<3; y++) {//loop to create 72 labels, each Label Transverse spacing 135-130=5, longitudinal spacing 30-28=2, Uilabel *lab = [Uilabel alloc]initwithframe:cgrectmake (Y*135+7, x*30+20, 130, 28)];
Lab.backgroundcolor = [Uicolor colorwithred:0.820 green:0.971 blue:1.000 alpha:1.000];
Lab.text = @ "HelloWorld";
Add the created label to the variable array [Labarr Addobject:lab];
}///Use a For loop to set various font formats for the 72-label font for (int i=0; i<72; i++) {Uilabel *lab = [Labarr objectatindex:i];
NSString *fontstring = [Fontarray objectatindex:i];
Lab.font = [Uifont fontwithname:fontstring size:18];
[Self.view Addsubview:[labarr objectatindex:i]];
}-(void) didreceivememorywarning {[Super didreceivememorywarning];
Dispose of any of the can is recreated.
} @end
The above is the entire content of this article, I hope to help you learn.