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

iOS新手入门之UILable

2015-10-07 11:06 399 查看
UILable可以在上面显示字体

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (void)dealloc
{
[_window release];
[super dealloc];
}

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

// 创建一个UILable
UILabel *aLable = [[UILabel alloc] initWithFrame:(CGRectMake(100, 100, 200, 200))];
// 给UILable添加背景颜色
aLable.backgroundColor = [UIColor greenColor];
// 在UILable上添加文本
aLable.text = @"我叫王大锤";
// 设置字体颜色
aLable.textColor = [UIColor blueColor];
// 设置文本是否居中
aLable.textAlignment = NSTextAlignmentCenter;
// 设置文本行数 如果行数设置为0 在lable足够大的情况下 可以把文本显示完整 自动换行
aLable.numberOfLines = 0;
// 设置字体大小
aLable.font = [UIFont systemFontOfSize:30];

// 下面两个不常用 几乎不用
// 设置阴影
aLable.shadowColor = [UIColor whiteColor];
// 设置阴影位置
aLable.shadowOffset = CGSizeMake(10, 10);

// 把aLable显示出来 也就是添加到window上
[self.window addSubview:aLable];
// 释放lable
[aLable release];
}


Xcode6.0之后 UILable添加到另外一个UILable上时 如果UILable上没有文本 那么前者就显示不出来
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: