Adding Labels As subview to UIView

iphone, uilabel, uiview

Solution

Add the labels to GreeView like this,

Eg:

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

Hope this will help you.

Problem

can anyone tell me how to add two labels for a view that i was added on UITableView Cell.i have created that view as UIView with some name.and i have created two labels in UIView class and also set frame for labels,set text and etc.my problem is am getting that view in tableview cell but not those labels. ``` 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]; ``` this is just i am setting frame,text to labels like that in a 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]; ``` and here i am adding that UIView to a tableview cell.and i dont know how to add those labels to my UIView. please help me. sorry if any mistakes in english. anyone please help me. thanks alot in advance.

Original source