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

ios学习第五天(四)UILabel的使用

2017-04-11 15:44 344 查看
UILabel是UIView的子类,是标签的意思,可以在上面写一段文字,下面是UILabel的声名的头部

NS_CLASS_AVAILABLE_IOS(2_0) @interface UILabel : UIView <NSCoding>

和前面一样,先看效果:



效果很简单,就是一个圆角红色背景,白色的带阴影的字体大小未知的居中的一个label

怎么做呢,可以按照前面的方式创建一个项目,在ViewController.m中加入下面这段代码

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 250, 60)];//创建一个UILabel
[self.view addSubview:label];//添加label为子view

label.backgroundColor=[UIColor redColor];
label.text=@"召唤效果";
label.textColor=[UIColor whiteColor];//设置文字颜色为白色
label.textAlignment=NSTextAlignmentCenter;//居中显示
label.font=[UIFont systemFontOfSize:40 weight:60];//设置字体

label.shadowColor=[[UIColor alloc] initWithRed:0.7 green:0.7 blue:0.7 alpha:0.7];//设置阴影灰色
label.shadowOffset=CGSizeMake(2, 2);//设置阴影偏移值

//设置圆角
label.layer.cornerRadius=8;
label.layer.masksToBounds=YES;

label.center=self.view.center;

}

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

@end


在AppDelegate.m中的(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  函数下加入这些东西
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor=[UIColor whiteColor];
[self.window makeKeyAndVisible];
self.window.rootViewController=[[ViewController alloc] init];
return YES;
}

IOS UI部分主要学习各种继承自UIView的控件,大部分控件使用方法类似,看看ios中的部分UI控件家族图谱:



接下来几篇,介绍UIButton和UIImageView,其他的以后项目中有需求,自行学习就好了,还需要学习控件美化,自定义控件等。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: