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

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,其他的以后项目中有需求,自行学习就好了,还需要学习控件美化,自定义控件等。








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值