2012-08-22 107 views
5

誰能告訴我如何添加兩個標籤,但我仍然在UITableView的Cell.i增加了一個圖已經創建了一個視圖的UIView一些name.and我已經創建了UIView類兩個標籤和還設置標籤框架,設置文本等。我​​的問題是在桌面單元中獲取該視圖,但不是那些標籤。添加標籤作爲子視圖的UIView

countLabel.text = @"4"; 
    countLabel.frame=CGRectMake(275, 10, 20, 15); 
    countLabel.font=[UIFont boldSystemFontOfSize:15.0]; 
    countLabel.textColor=[UIColor colorWithWhite:0.0 alpha:0.5]; 
    countLabel.backgroundColor=[UIColor clearColor]; 

    hrsLabel.text = @"Hours"; 
    hrsLabel.frame=CGRectMake(260, 30, 45, 15); 
    hrsLabel.font=[UIFont boldSystemFontOfSize:15.0]; 
    hrsLabel.textColor=[UIColor colorWithWhite:0.0 alpha:0.5]; 
    hrsLabel.backgroundColor=[UIColor clearColor]; 

這僅僅是我設置框,文本像標籤在UIView.and

GreenView *greenView = [[GreenView alloc] initWithFrame:CGRectMake(250, 8, 60, 50)]; 
greenView.backgroundColor = [UIColor colorWithRed:0.000 green:0.690 blue:0.313 alpha:0.5]; 
[cell.contentView addSubview:greenView]; 

我在這裏補充說UIView的一個實現代碼如下cell.and我不知道如何將這些標籤添加到我的UIView。請幫幫我。

對不起,如果用英文任何錯誤。 任何人都請幫助我。 提前感謝。

+0

你能分享你在哪裏添加標籤UIView的代碼? –

+0

添加這些行, [self.contentView addSubview:countLabel]; [self.contentView addSubview:hrsLabel]; –

+0

這段代碼是在單獨的單元類中嗎?如果是這樣,你需要分配標籤。 –

回答

2

標籤添加到GreeView這樣,

如:

GreenView *greenView = [[GreenView alloc] initWithFrame:CGRectMake(250, 8, 60, 50)]; 
    greenView.backgroundColor = [UIColor colorWithRed:0.000 green:0.690 blue:0.313 alpha:0.5]; 

    countLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 20, 15)]; 
    countLabel.text = @"4"; 
    countLabel.font=[UIFont boldSystemFontOfSize:15.0]; 
    countLabel.textColor=[UIColor whiteColor]; 
    countLabel.backgroundColor=[UIColor clearColor]; 
    [greenView addSubview:countLabel]; 

    hrsLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 40, 45, 15)]; 
    hrsLabel.text = @"Hours"; 
    hrsLabel.font=[UIFont boldSystemFontOfSize:15.0]; 
    hrsLabel.textColor=[UIColor whiteColor]; 
    hrsLabel.backgroundColor=[UIColor clearColor]; 
    [greenView addSubview:hrsLabel]; 

    [cell.contentView addSubview:greenView]; 

希望這會幫助你。

+0

我認爲這是對標籤添加到tableviewCell.i需要在視圖這是目前在tableviewCell .. –

+0

沒錯添加標籤。我會更新。 –

1
countLabel.text = @"4"; 
countLabel.frame=CGRectMake(275, 10, 20, 15); 
countLabel.font=[UIFont boldSystemFontOfSize:15.0]; 
countLabel.textColor=[UIColor colorWithWhite:0.0 alpha:0.5]; 
countLabel.backgroundColor=[UIColor clearColor]; 

hrsLabel.text = @"Hours"; 
hrsLabel.frame=CGRectMake(260, 30, 45, 15); 
hrsLabel.font=[UIFont boldSystemFontOfSize:15.0]; 
hrsLabel.textColor=[UIColor colorWithWhite:0.0 alpha:0.5]; 
hrsLabel.backgroundColor=[UIColor clearColor]; 

    [greenView addSubview: countLabel]; 
    [greenView addSubview: hrsLabel]; 
    [cell.contentview addSubview:greenView]; 

    return cell; 
+0

是@ Rupesh.i與answer.but同意我創建的視圖的Objective-C在.m文件UIView.So的子類,我沒有得到[MyView的addSubView:]方法在這裏我得到了現在。因爲我只是添加像[自addSubview:countLbl]並感謝您的回覆 –

3

創建像標籤和標籤LABEL1並且添加的UIView

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, 250, 15)]; 

[label setText:@"Hello"]; 

UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, 250, 15)]; 

[label1 setText:@"Hello1"]; 

UIView *myView = [UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)]; 

[myView addSubview:label]; 
[myView addSubview:label1]; 
+0

這裏子視圖應該是子視圖我認爲 –

+0

是啊謝謝joshsverns –

1
countLabel.text = @"4"; 
countLabel.frame=CGRectMake(275, 10, 20, 15); 
countLabel.font=[UIFont boldSystemFontOfSize:15.0]; 
countLabel.textColor=[UIColor colorWithWhite:0.0 alpha:0.5]; 
countLabel.backgroundColor=[UIColor clearColor]; 

hrsLabel.text = @"Hours"; 
hrsLabel.frame=CGRectMake(260, 30, 45, 15); 
hrsLabel.font=[UIFont boldSystemFontOfSize:15.0]; 
hrsLabel.textColor=[UIColor colorWithWhite:0.0 alpha:0.5]; 
hrsLabel.backgroundColor=[UIColor clearColor]; 

[self addSubView:countLabel]; 
[self addSubView:hrsLabel]; 

最後我得到了我的回答如上。非常感謝你的回覆。

相關問題