In IOS, use the [UIFont familyNames] method to obtain 72 system fonts.
Use [UIFont fontWithName:@"Zapfino" size:18] to set the font and font size for text in the space.
Controls can be defined in batches and properties can be set through a for loop.
The following program obtains 72 fonts in the system and stores them in an array. There are two ways. One is to get each font through a for loop and add it to a variable array, and the other is to directly assign 72 fonts to an array.
Note: When there are fewer page controls, choose to create each control manually. When the number of controls is large and the arrangement is regular, use loop batch creation. The size of the control can be automatically adapted to the device by obtaining the resolution of the hardware device. The specific method is:
//Screen sizeCGRect rect = [[UIScreen mainScreen] bounds]; CGSize size = ; CGFloat width = ; CGFloat height = ; NSLog(@"print %f,%f",width,height); //ResolutionCGFloat scale_screen = [UIScreen mainScreen].scale; width*scale_screen,height*scale_screen
Program content:
#import "" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Define a variable array to store all fonts NSMutableArray *fontarray = [NSMutableArray arrayWithCapacity:10]; // traverse UI fonts for (id x in [UIFont familyNames]) { NSLog(@"%@",x); [fontarray addObject:x]; } // Storing the font directly into the array NSArray *fontarrauy2 = [UIFont familyNames]; NSLog(@"%@",fontarrauy2); // Create a label to display a string that sets a certain font UILabel *mylab1 = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 200, 50)]; = [UIFont systemFontOfSize:20]; = [UIFont fontWithName:@"Zapfino" size:18]; = [UIFont fontWithName:[fontarray objectAtIndex:10] size:18]; = @"HelloWorld"; [ addSubview:mylab1]; // Create a new variable array to store labels created in batches using for loops NSMutableArray *labarr = [NSMutableArray arrayWithCapacity:100]; for (int x=0; x<24; x++) { for (int y=0; y<3; y++) { // Create 72 labels in loop, each label is horizontally spacing 135-130=5, and vertical spacing 30-28=2, UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(y*135+7, x*30+20, 130, 28)]; = [UIColor colorWithRed:0.820 green:0.971 blue:1.000 alpha:1.000]; = @"HelloWorld"; // Add the created label to a variable array [labarr addObject:lab]; } } // Use a for loop to set various font formats for 72 labels fonts for (int i=0; i<72; i++) { UILabel *lab = [labarr objectAtIndex:i]; NSString *fontstring = [fontarray objectAtIndex:i]; = [UIFont fontWithName:fontstring size:18]; [ addSubview:[labarr objectAtIndex:i]]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
The above is all about this article, I hope it will be helpful to everyone's learning.