UILabel

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UILabel相关的知识,希望对你有一定的参考价值。

UILabel是?来显??本的控件,是在app中出镜率最?的控件。UILabel同样是UIView的?类主要是??扩展了UIView的显??字功能。    
创建?个UILabel,遵循以下?个步骤来完成:  
1、alloc开辟空间,然后initWithFrame来初始化??; 
2、设置UILabel的相关属性,也就是我们想要的属性     
3、把label添加到?视图(UIView)上,才可以显?出来;
  //
//  ViewController.m
//  UILabel01
//
//  Created by cqy on 16/2/13.
//  Copyright © 2016年 程清杨. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 20, 100, 50)];
    label.backgroundColor = [UIColor brownColor];
    [self.view addSubview:label];
    //text:要显?的?本内容
    label.text = @"你真美!优点喜欢你了!";
    //textColor:来修改要显?的?字的颜?
    label.textColor = [UIColor redColor];
    //textAlignment:要显?的?字的对其?式(?平?向)
    label.textAlignment = NSTextAlignmentLeft;
    //fond:设置?字的字体和字号
    label.font = [UIFont fontWithName:@"Helvetica-Bold"size:20];
    //numberOflines:在label若是?字太长,就会?动省略后?的字,numberOfLines是为了展?省略的?字。给多少?,就显?多少?,显?完毕为?。
    label.numberOfLines = 0;
    //lineBreakMode:断?的模式,根据什么换
    label.lineBreakMode = NSLineBreakByCharWrapping;//根据单词为单位换行
    //shadowColor:设置?字的阴影颜?
    label.shadowColor = [UIColor blueColor];
    //shadowOffset:设置文字阴影
    label.shadowOffset = CGSizeMake(2, 1);//阴影向x正?向偏移2,向y正?向偏移1
    // Do any additional setup after loading the view, typically from a nib.
}

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

@end
  

以上是关于UILabel的主要内容,如果未能解决你的问题,请参考以下文章

IOS代码布局 UILabel

为啥这个自定义 UIView 代码不显示 UILabel 的?

根据步进值动态改变字体大小

iOS开发UILabel的公共属性及拓展属性

UILabel 添加 GradientLayer [重复]

UILabel范例实现代码如下