您的位置:首页 > 移动开发 > Objective-C

Objective-C语言——UILabel标签

2016-01-06 08:55 671 查看
Objective-C语言——UILabel标签

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

//获取屏幕的尺寸
//    UIScreen *screen = [UIScreen mainScreen];
//    CGFloat width = screen.bounds.size.width; //宽
//    CGFloat height = screen.bounds.size.height; //高
////或
//    CGFloat width = [UIScreen mainScreen].bounds.size.width; // 宽
//    CGFloat height = [UIScreen mainScreen].bounds.size.height; //高

//UILabel
//初始化
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
//    UILabel *label = [[UILabel alloc] init];

label.frame = CGRectMake(ScreenWidth/2-150, ScreenHeight/2-150, 300, 300);

//文本内容
label.text = @"Don't be a woman that needs a man, Be a woman a man needs.Don't be a woman that needs a man, Be a woman a man needs.Don't be a ";

//字体大小
label.font = [UIFont systemFontOfSize:30];

//找出所有的字体样式
NSArray *familyNamesArray = [UIFont familyNames];
NSLog(@"%@",familyNamesArray);

for (NSString *a in [UIFont familyNames]) {
NSLog(@"%@",a);

}

//只对英文和数字有效
label.font = [UIFont fontWithName:@"Bodoni 72 Oldstyle" size:32];

//加粗
label.font = [UIFont boldSystemFontOfSize:20];

//文本颜色
label.textColor = [UIColor yellowColor];

//在 label 中使文本换行
label.numberOfLines = 0; //0代表不限制label 的行数

//文本对齐方式,默认是NSTextAlignmentLeft,   textAlignment是枚举
//    label.textAlignment = NSTextAlignmentCenter; // label.textAlignment = 1;

//设置文本过长时的显示格式
//    label.lineBreakMode = NSLineBreakByTruncatingMiddle;//  "ab...yz"

//label 背景颜色
label.backgroundColor = [UIColor purpleColor];

//view 背景颜色
self.view.backgroundColor = [UIColor yellowColor];

//Label文字大小自适应
[label sizeToFit];

//    //边框
//    label.layer.borderColor = [[UIColor magentaColor] CGColor];
//    label.layer.borderWidth = 5;
//

label.enabled = NO;

//显示在 view
[self.view addSubview:label];

//初始化
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectZero];

NSString *string = @"Don't be a woman that needs a man, Be a woman a man needs.Don't be a woman that needs a man, Be a woman a man needs.Don't be a woman that needs a man, Be a woman a man needs.Don't be a woman that needs a man, Be a woman a man needs.Don't be a woman that needs a man, Be a woman a man needs.Don't be a woman that needs a man, Be a woman a man needs.";
label1.text = string;

label1.frame = CGRectMake(ScreenWidth/2-150, ScreenHeight/2-150, 300, 300);

label1.backgroundColor = [UIColor blueColor];

label1.font = [UIFont systemFontOfSize:18];

CGSize size = [string sizeWithAttributes:@{NSFontAttributeName:label1.font}];

label1.frame = CGRectMake(ScreenWidth/2 - size.width/2, ScreenHeight/2 - size.height/2, size.width, size.height);

//    [self.view addSubview:label1];

}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end


运行结果

2016-01-06 08:57:33.589 UI_01_01[568:7164] (
Copperplate,
"Heiti SC",
"Iowan Old Style",
"Kohinoor Telugu",
Thonburi,
"Heiti TC",
"Courier New",
"Gill Sans",
"Apple SD Gothic Neo",
"Marker Felt",
"Avenir Next Condensed",
"Tamil Sangam MN",
"Helvetica Neue",
"Gurmukhi MN",
"Times New Roman",
Georgia,
"Apple Color Emoji",
"Arial Rounded MT Bold",
Kailasa,
"Kohinoor Devanagari",
"Kohinoor Bangla",
"Chalkboard SE",
"Sinhala Sangam MN",
"PingFang TC",
"Gujarati Sangam MN",
Damascus,
Noteworthy,
"Geeza Pro",
Avenir,
"Academy Engraved LET",
Mishafi,
Futura,
Farah,
"Kannada Sangam MN",
"Arial Hebrew",
Arial,
"Party LET",
Chalkduster,
"Hoefler Text",
Optima,
Palatino,
"Lao Sangam MN",
"Malayalam Sangam MN",
"Al Nile",
"Bradley Hand",
"PingFang HK",
"Trebuchet MS",
Helvetica,
Courier,
Cochin,
"Hiragino Mincho ProN",
"Devanagari Sangam MN",
"Oriya Sangam MN",
"Snell Roundhand",
"Zapf Dingbats",
"Bodoni 72",
Verdana,
"American Typewriter",
"Avenir Next",
Baskerville,
"Khmer Sangam MN",
Didot,
"Savoye LET",
"Bodoni Ornaments",
Symbol,
Menlo,
"Bodoni 72 Smallcaps",
Papyrus,
"Hiragino Sans",
"PingFang SC",
"Euphemia UCAS",
"Telugu Sangam MN",
"Bangla Sangam MN",
Zapfino,
"Bodoni 72 Oldstyle"
)
2016-01-06 08:57:33.590 UI_01_01[568:7164] Copperplate
2016-01-06 08:57:33.590 UI_01_01[568:7164] Heiti SC
2016-01-06 08:57:33.590 UI_01_01[568:7164] Iowan Old Style
2016-01-06 08:57:33.591 UI_01_01[568:7164] Kohinoor Telugu
2016-01-06 08:57:33.591 UI_01_01[568:7164] Thonburi
2016-01-06 08:57:33.591 UI_01_01[568:7164] Heiti TC
2016-01-06 08:57:33.591 UI_01_01[568:7164] Courier New
2016-01-06 08:57:33.591 UI_01_01[568:7164] Gill Sans
2016-01-06 08:57:33.592 UI_01_01[568:7164] Apple SD Gothic Neo
2016-01-06 08:57:33.592 UI_01_01[568:7164] Marker Felt
2016-01-06 08:57:33.592 UI_01_01[568:7164] Avenir Next Condensed
2016-01-06 08:57:33.592 UI_01_01[568:7164] Tamil Sangam MN
2016-01-06 08:57:33.592 UI_01_01[568:7164] Helvetica Neue
2016-01-06 08:57:33.592 UI_01_01[568:7164] Gurmukhi MN
2016-01-06 08:57:33.593 UI_01_01[568:7164] Times New Roman
2016-01-06 08:57:33.593 UI_01_01[568:7164] Georgia
2016-01-06 08:57:33.593 UI_01_01[568:7164] Apple Color Emoji
2016-01-06 08:57:33.593 UI_01_01[568:7164] Arial Rounded MT Bold
2016-01-06 08:57:33.593 UI_01_01[568:7164] Kailasa
2016-01-06 08:57:33.593 UI_01_01[568:7164] Kohinoor Devanagari
2016-01-06 08:57:33.594 UI_01_01[568:7164] Kohinoor Bangla
2016-01-06 08:57:33.594 UI_01_01[568:7164] Chalkboard SE
2016-01-06 08:57:33.594 UI_01_01[568:7164] Sinhala Sangam MN
2016-01-06 08:57:33.594 UI_01_01[568:7164] PingFang TC
2016-01-06 08:57:33.594 UI_01_01[568:7164] Gujarati Sangam MN
2016-01-06 08:57:33.595 UI_01_01[568:7164] Damascus
2016-01-06 08:57:33.595 UI_01_01[568:7164] Noteworthy
2016-01-06 08:57:33.595 UI_01_01[568:7164] Geeza Pro
2016-01-06 08:57:33.595 UI_01_01[568:7164] Avenir
2016-01-06 08:57:33.595 UI_01_01[568:7164] Academy Engraved LET
2016-01-06 08:57:33.595 UI_01_01[568:7164] Mishafi
2016-01-06 08:57:33.596 UI_01_01[568:7164] Futura
2016-01-06 08:57:33.596 UI_01_01[568:7164] Farah
2016-01-06 08:57:33.596 UI_01_01[568:7164] Kannada Sangam MN
2016-01-06 08:57:33.596 UI_01_01[568:7164] Arial Hebrew
2016-01-06 08:57:33.596 UI_01_01[568:7164] Arial
2016-01-06 08:57:33.596 UI_01_01[568:7164] Party LET
2016-01-06 08:57:33.597 UI_01_01[568:7164] Chalkduster
2016-01-06 08:57:33.597 UI_01_01[568:7164] Hoefler Text
2016-01-06 08:57:33.597 UI_01_01[568:7164] Optima
2016-01-06 08:57:33.597 UI_01_01[568:7164] Palatino
2016-01-06 08:57:33.597 UI_01_01[568:7164] Lao Sangam MN
2016-01-06 08:57:33.597 UI_01_01[568:7164] Malayalam Sangam MN
2016-01-06 08:57:33.597 UI_01_01[568:7164] Al Nile
2016-01-06 08:57:33.598 UI_01_01[568:7164] Bradley Hand
2016-01-06 08:57:33.598 UI_01_01[568:7164] PingFang HK
2016-01-06 08:57:33.598 UI_01_01[568:7164] Trebuchet MS
2016-01-06 08:57:33.598 UI_01_01[568:7164] Helvetica
2016-01-06 08:57:33.598 UI_01_01[568:7164] Courier
2016-01-06 08:57:33.599 UI_01_01[568:7164] Cochin
2016-01-06 08:57:33.599 UI_01_01[568:7164] Hiragino Mincho ProN
2016-01-06 08:57:33.599 UI_01_01[568:7164] Devanagari Sangam MN
2016-01-06 08:57:33.599 UI_01_01[568:7164] Oriya Sangam MN
2016-01-06 08:57:33.599 UI_01_01[568:7164] Snell Roundhand
2016-01-06 08:57:33.599 UI_01_01[568:7164] Zapf Dingbats
2016-01-06 08:57:33.600 UI_01_01[568:7164] Bodoni 72
2016-01-06 08:57:33.600 UI_01_01[568:7164] Verdana
2016-01-06 08:57:33.600 UI_01_01[568:7164] American Typewriter
2016-01-06 08:57:33.600 UI_01_01[568:7164] Avenir Next
2016-01-06 08:57:33.600 UI_01_01[568:7164] Baskerville
2016-01-06 08:57:33.600 UI_01_01[568:7164] Khmer Sangam MN
2016-01-06 08:57:33.601 UI_01_01[568:7164] Didot
2016-01-06 08:57:33.601 UI_01_01[568:7164] Savoye LET
2016-01-06 08:57:33.601 UI_01_01[568:7164] Bodoni Ornaments
2016-01-06 08:57:33.601 UI_01_01[568:7164] Symbol
2016-01-06 08:57:33.601 UI_01_01[568:7164] Menlo
2016-01-06 08:57:33.601 UI_01_01[568:7164] Bodoni 72 Smallcaps
2016-01-06 08:57:33.602 UI_01_01[568:7164] Papyrus
2016-01-06 08:57:33.602 UI_01_01[568:7164] Hiragino Sans
2016-01-06 08:57:33.602 UI_01_01[568:7164] PingFang SC
2016-01-06 08:57:33.602 UI_01_01[568:7164] Euphemia UCAS
2016-01-06 08:57:33.602 UI_01_01[568:7164] Telugu Sangam MN
2016-01-06 08:57:33.602 UI_01_01[568:7164] Bangla Sangam MN
2016-01-06 08:57:33.603 UI_01_01[568:7164] Zapfino
2016-01-06 08:57:33.603 UI_01_01[568:7164] Bodoni 72 Oldstyle

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