UI3

it2024-10-23  20

// // AppDelegate.m // UI3_UILabel // // Created by zhangxueming on 15/6/29. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import "AppDelegate.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. //UILabel 继承与 UIView //用来显示文字, 不可以编辑 UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, self.window.frame.size.width-20, 50)]; //把label1添加到window上显示 [self.window addSubview:label1];//默认颜色是clearColor //修改背景颜色 label1.backgroundColor = [UIColor cyanColor]; //设置文本 label1.text = @"千锋教育"; //设置文字对齐方式 //NSTextAlignmentLeft 居左对齐 //NSTextAlignmentCenter 居中对齐 //NSTextAlignmentRight 居右对齐 label1.textAlignment = NSTextAlignmentCenter;//居中对齐 //设置文字颜色 label1.textColor = [UIColor redColor]; //设置文字阴影偏移位置 label1.shadowOffset = CGSizeMake(5, -5); label1.shadowColor = [UIColor blackColor]; //设置高亮状态颜色 label1.highlighted = NO;//设置文字的高亮状态 label1.highlightedTextColor = [UIColor blueColor]; UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(10, 200, self.window.frame.size.width-20, 100)]; label2.backgroundColor = [UIColor yellowColor]; label2.text = @"hello world hello world hello world hello world hello world hello world hello world hello world hello worldhello world中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国中国helloworld"; label2.textAlignment = NSTextAlignmentCenter; //自适应字体宽度 label2.adjustsFontSizeToFitWidth = YES; label2.minimumScaleFactor = 0.0; //NSLineBreakByTruncatingHead //NSLineBreakByTruncatingTail(默认) //NSLineBreakByTruncatingMiddle label2.lineBreakMode = NSLineBreakByTruncatingMiddle; //NSLineBreakByCharWrapping-->以字符截断换行 //NSLineBreakByWordWrapping-->以单词截断换行 //NSLineBreakByClipping-->剪裁多余的文本内容 label2.numberOfLines = 0;//numberOfLines=0 显示多行 label2.lineBreakMode = NSLineBreakByClipping;// UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(10, 350, self.window.frame.size.width-20, 50)]; label3.backgroundColor = [UIColor cyanColor]; [self.window addSubview:label3]; label3.text = @"中国教育-hello world"; label3.textAlignment = NSTextAlignmentCenter; label3.textColor = [UIColor blueColor]; //默认字体大小是17 //设置字体大小 label3.font = [UIFont boldSystemFontOfSize:30]; //遍历字体库 //获取所有的字体簇 NSArray *familyFonts =[UIFont familyNames]; for (NSString *familyName in familyFonts) { //获取字体簇所有的字体 NSArray *fonts = [UIFont fontNamesForFamilyName:familyName]; for (NSString *fontName in fonts) { NSLog(@"name = %@", fontName); } } label3.font = [UIFont fontWithName:@"SnellRoundhand-Bold" size:24]; [self.window addSubview:label2]; self.window.backgroundColor = [UIColor whiteColor]; self.window.rootViewController = nil; return YES; }

 

转载于:https://www.cnblogs.com/0515offer/p/4638278.html

最新回复(0)