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

UILabel

2015-08-05 21:30 337 查看
#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (void)dealloc
{
// 对应属性里边那个strong(retain)
[_window release];
[super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor cyanColor];
[self.window makeKeyAndVisible];
[_window release];

// UILabel(标签) 是显示文本(在视图上显示文字)的控件 在App中是出现频率最高的控件
// 它是UIView的子类,扩展了文字显示的功能,它是能显示文字的视图
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
label.backgroundColor = [UIColor orangeColor];
[self.window addSubview:label];
[label release];

// 设置文本内容
label.text = @"天山童姥afgaj";
// 文本内容的颜色
label.textColor = [UIColor blackColor];
// 文本的对齐方式
label.textAlignment = NSTextAlignmentCenter;
// 文本字体大小 font
label.font = [UIFont systemFontOfSize:30];
label.font = [UIFont fontWithName:@"Helvetica-Bold" size:30];   // 黑体加粗

// 文本行数
// 设置行数 默认是一行,设置几行就是显示几行,注意label的高度要能容纳行数
// 如果行数没能显示完信息,没显示的信息以省略号代替
// 设置成0是行数的最大值
label.numberOfLines = 0;

// 文本换行模式 以单词为单位换行
// 让文本自己去适应label的尺寸,显示全部内容
// 断行模式
label.lineBreakMode = NSLineBreakByTruncatingMiddle;

// 文本阴影
// 阴影颜色
//    label.shadowColor = [UIColor redColor];
// 阴影大小 阴影向x正方向偏移2,向y正方向偏移10.
//    label.shadowOffset = CGSizeMake(2, 10);

// 设置圆角和边框
label.layer.borderWidth = 1;
// 幅度
label.layer.cornerRadius = 10;
label.layer.masksToBounds = YES;
label.frame = CGRectMake(100, 100, 200, 200);
// center可以修改视图的位置
label.center = CGPointMake(100+75, 100+75);

return YES;
}

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