AppDelegate.m
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
1.需要加入dealloc方法.
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
2.初始化一个window.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
[_window release];
3.在window上添加一个label1.
UILabel *label1 = [UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 200);
label1.backgroundColor = [UIColor yellowColor];
[self.window addSubview:label1];
[label1 release];
4.设置文本内容.
label1.text = @"Messi";
5.设置文本内容的颜色.
label1.textColor = [UIColor blueColor];
6.设置文本的对其方式.
label1.textAlignment = NSTextAlignmentCenter;
7.设置字体大小.
label1.font = [UIFont systemFontOfSize:18];
8.设置行数,默认是一行.如果设置当前的最大行数为零,说明让系统自动寻找适应的行数(两种方法).
label1.numberOfLines = 0;
label1.numberOfLines = NSIntegerMax;
9.设置text的自适应区,要想它能自适应,必须先设置文本内容,再设置行数和自适应.
[label1 sizeToFit];
10.设置断行模式.
label1.lineBreakMode = NSLineBreakByTruncatingMiddle;
11.设置阴影颜色.
label1.shadowColor = [UIColor blackColor];
12.设置阴影大小.
label1.shadowOffset = CGSizeMake(2,1);
13.设置边框.
label1.layer.borderWidth = 1;
14.设置圆角.
label1.layer.cornerRadius = 15;
15.设置内容都在圆角内.
label1.layer.masksToBounds = YES;
16.给框矩形框架重新赋值.
label1.frame = CGRectMake(100, 100, 200, 200);
17.以中心为原点,移动响应位置.如果中心的坐标长度(x,y)正好为边长的1/2,即(x/2,y/2),那么该图形在框架的顶点位置.
括号中的x,y为卫衣长度.
label1.center = CGPointMake(100+x,100+y);
return YES;
}
@end
UI02_Label
最新推荐文章于 2021-05-27 06:17:36 发布