您的位置:首页 > 产品设计 > UI/UE

IOS开发之UILabel

2016-04-06 00:00 405 查看
摘要: IOS开发之UILabel

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.

_window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

[_window setBackgroundColor:[UIColor cyanColor]];

#pragma mark UILabel的创建
//====================UILabel的创建=====================
//UILabel:UIView UIView属性和方法UILabel都拥有
//作用是专门用来显示文字的控件
//1.创建一个UILabel对象
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake
(50, 50, 250, 600)];

//2.设置背景颜色
label.backgroundColor = [UIColor yellowColor];

//3.显示在界面上
[_window addSubview:label];

#pragma mark label相关属性
//==================label相关属性=======================
//4.设置文本内容text
[label setText:@"Hello LuHan Hello LuHan Hello LuHan Hello LuHan Hello LuHan Hello LuHan Hello LuHan Hello LuHan Hello LuHanHello LuHan !!"];

//5.设置字体
//UIFont是UI字体类;创建系统字体并且设置字体大小;
[label setFont:[UIFont systemFontOfSize:20]];

//系统默认加粗字体;
// UIFont *font1 = [UIFont boldSystemFontOfSize:15];

//系统默认斜体
UIFont *font2 = [UIFont italicSystemFontOfSize:30];

//拿到当前系统支持的所有的字体名
NSArray *allFontName = [UIFont familyNames];
// NSLog(@"%@",allFontName);
//设置字体名和字体大小;
UIFont *font3 = [UIFont fontWithName:@"Zapfino" size:20];

//ttf字体库的文件后缀(自学内容)
[label setFont:font3];

//6.设置文字颜色(默认黑色)
label.textColor = [UIColor redColor];

//7.设置阴影颜色
label.shadowColor = [UIColor blackColor];

//8.设置阴影偏移
[label setShadowOffset:CGSizeMake(-2, -2)];

//9.设置字体的对齐模式
//NSTextAlignmentLeft(默认是居左的);
//NSTextAlignmentCenter
//NSTextAlignmentRight
[label setTextAlignment:NSTextAlignmentLeft];

//10.设置换行模式
// NSLineBreakByWordWrapping = 0, //以单词为单位换行,显示不了的内容以
//单词截断,后面的直接不显示;
// NSLineBreakByCharWrapping, /* Wrap at character boundaries */
// NSLineBreakByClipping,//还是以单词换行,
//最后显示不全的部分在label后面直接截断,后面直接不显示
// NSLineBreakByTruncatingHead,//显示不全,最后一行将最后的内容显示前面使用...代替;
// NSLineBreakByTruncatingTail, /* Truncate at tail of line: "abcd..." */
// NSLineBreakByTruncatingMiddle /* Truncate middle of line: "ab...yz" */

[label setLineBreakMode:NSLineBreakByWordWrapping];

//11.设置显示的行数;(要适应label的高度!!)
[label setNumberOfLines:3];

//12.自动换行
//a.设置行数为0
[label setNumberOfLines:0];
//b.设置自动换行模式
[label setLineBreakMode:NSLineBreakByWordWrapping];

//13.自适应宽度(将字体缩放,让所有的文字都显示出来);
[label setAdjustsFontSizeToFitWidth:YES];

[_window makeKeyAndVisible];

return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  IOS开发之UILabel