2012-08-22 33 views
5

bất cứ ai có thể cho tôi biết cách thêm hai nhãn cho chế độ xem mà tôi đã được thêm vào UITableView Cell.i đã tạo chế độ xem đó là UIView với một số tên. Và tôi đã tạo hai nhãn trong lớp UIView và cũng thiết lập khung cho nhãn, thiết lập văn bản và vv vấn đề của tôi là nhận được rằng xem trong ô xem bảng nhưng không phải là những nhãn.Thêm nhãn Khi xem phụ cho 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]; 

này chỉ là tôi đang thiết lập khung hình, văn bản để các nhãn như rằng trong một 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]; 

và ở đây tôi đang nói thêm rằng UIView để một cell.and tableview tôi không biết làm thế nào để thêm các nhãn đó vào UIView của tôi. làm ơn giúp tôi.

xin lỗi nếu có lỗi trong tiếng Anh. bất cứ ai hãy giúp tôi. cảm ơn rất nhiều trước.

+0

Bạn có thể chia sẻ mã nơi bạn đang thêm nhãn vào UIView không? –

+0

Thêm các dòng này, [self.contentView addSubview: countLabel]; [self.contentView addSubview: giờLabel]; –

+0

Mã này có nằm trong một lớp ô riêng biệt không ?. Nếu vậy, bạn cần phải phân bổ các nhãn. –

Trả lời

2

Thêm nhãn để GreeView như thế này,

Ví dụ:

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]; 

Hy vọng điều này sẽ giúp bạn.

+0

tôi nghĩ rằng đây là để thêm nhãn để tableviewCell.i cần phải thêm nhãn trên xem đó là hiện diện trong tableviewCell .. –

+0

Yep. Tôi sẽ cập nhật. –

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

yes @ Rupesh.i đồng ý với answer.but của bạn tôi tạo ra rằng xem như Mục tiêu-C với phân lớp của UIView.So trong tập tin .m không nhận được [myView addSubView:] phương pháp ở đây tôi đã nhận nó ngay bây giờ.như tôi chỉ cần thêm như [tự addSubview: countLbl] và nhờ trả lời của bạn –

3

tạo nhãn như nhãn và label1 và thêm vào 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

ở đây SubView nên được Subview Tôi nghĩ rằng –

+0

yeah Thanks 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]; 

Cuối cùng tôi Got câu trả lời của tôi như trên. Cảm ơn rất nhiều cho tất cả các trả lời ur.

Các vấn đề liên quan