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,其他的以后项目中有需求,自行学习就好了,还需要学习控件美化,自定义控件等。
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,其他的以后项目中有需求,自行学习就好了,还需要学习控件美化,自定义控件等。
相关文章推荐
- IOS 学习笔记(4) 控件 标签(UILabel)的使用方法
- 【ios开发学习 - 第六课】UILabel使用
- iOS学习笔记10—UILabel设置自动使用高和换行
- iOS学习5:UILabel的使用 (文字颜色,高度,行数) 设置
- iOS开发学习笔记之UILabel的使用
- ios学习第五天(六)UIImageView的使用
- iOS学习之分段Table View的使用(Grouped样式表格)
- IOS学习之Tab Bar的使用和视图切换
- ios学习--UILabel学习随笔
- IOS学习之十二:Core Location定位和MapKit视图使用
- iOS菜鸟学习—— NSSortDescriptor的使用
- iOS学习之iOS 使用NINetworkImageView下载图片,google地图图片的获取。
- IOS学习之Tab Bar的使用和视图切换
- ios学习--NSInvocationOperation使用
- IOS学习4 UIActionSheet的使用
- iOS学习之UIActionSheet的使用
- IOS学习3 Tab Bar的使用和视图切换
- IOS开发学习笔记(1)-----UILabel 详解(原创)
- ios学习--openURL的使用方法
- ios学习--SQLite3的使用