位置:首页 > 手机开发 > iOS在线教程 > iOS - Labels(标签)

iOS - Labels(标签)

Label标签用法

IOS中 Label(标签)用于显示静态的内容,可以是一个单一的一行或多行。

 

重要的属性

  • textAlignment

  • textColor

  • text

  • numberOflines

  • lineBreakMode

添加一个自定义的方法addLabel

-(void)addLabel{
    UILabel *aLabel = [[UILabel alloc]initWithFrame:
    CGRectMake(20, 200, 280, 80)];
    aLabel.numberOfLines = 0;
    aLabel.textColor = [UIColor blueColor];
    aLabel.backgroundColor = [UIColor clearColor];
    aLabel.textAlignment = UITextAlignmentCenter;
    aLabel.text = @"This is a sample text
 of multiple lines.
    here number of lines is not limited.";
    [self.view addSubview:aLabel];
}

 

更新在ViewController.m 中方法 viewDidLoad 如下

- (void)viewDidLoad
{
    [super viewDidLoad];
    //The custom method to create our label is called
    [self addLabel];
    // Do any additional setup after loading the view, typically from a nib.
}

输出

现在,当我们运行程序时,我们会得到下面的输出

iOS Tutorial