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