iOS界面設計之UILabel的使用

-(void) initLabel
{
    //手動創建label
    label = [UILabel new];
    [label setText: @"關"];
    [label setTextColor: [UIColor redColor]];
    
    //設置控件居中
    CGRect superRect = [[UIScreen mainScreen] bounds];
    CGFloat superWidth = superRect.size.width;
    CGFloat superHeight = superRect.size.height;
    CGFloat labelWidth = superWidth / 4;
    CGFloat labelHeight = superWidth / 8;
    //位於屏幕中央
    label.frame = CGRectMake(superWidth/2-labelWidth/2, superHeight/2-labelHeight/2, labelWidth, labelHeight);
    
    [self.view addSubview:label];
    label.center = label.superview.center;
    //設置背景色 否則看不到邊界
    [label setBackgroundColor: [UIColor darkGrayColor]];
    //設置圓角
    label.layer.cornerRadius = 25;
    //設置此項才能看到圓角效果
    label.layer.masksToBounds = YES;
    //設置字體
    [label setFont: [UIFont fontWithName:@"Arial" size:20]];
    //設置文字居中
    [label setTextAlignment: NSTextAlignmentCenter];
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章