//屏幕尺寸 CGRect rect = [[UIScreen mainScreen] bounds]; CGSize size = rect.size; CGFloat width = size.width; CGFloat height = size.height; NSLog(@"print %f,%f",width,height); //分辨率 CGFloat scale_screen = [UIScreen mainScreen].scale; width*scale_screen,height*scale_screen
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 定义一个可变数组,用来存放所有字体
NSMutableArray *fontarray = [NSMutableArray arrayWithCapacity:10];
// 遍历UI字体
for (id x in [UIFont familyNames]) {
NSLog(@"%@",x);
[fontarray addObject:x];
}
// 直接把字体存储到数组中
NSArray *fontarrauy2 = [UIFont familyNames];
NSLog(@"%@",fontarrauy2);
// 创建一个label,用来显示设定某种字体的字符串
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];
// 新建一个可变数组,用来存放使用for循环批量创建的label
NSMutableArray *labarr = [NSMutableArray arrayWithCapacity:100];
for (int x=0; x<24; x++) {
for (int y=0; y<3; y++) {
// 循环创建72个label,每个label横向间距135-130=5,纵向间距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";
// 将创建好的label加入到可变数组
[labarr addObject:lab];
}
}
// 使用for循环给72个label的字体设置各种字体格式
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 resources that can be recreated.
}
@end
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有