2012-08-22 22 views
5

alguien me puede decir cómo agregar dos etiquetas para una vista que me agregaron en UITableView Cell. He creado esa vista como UIView con algún nombre. Y he creado dos etiquetas en la clase UIView y también establecí el marco para las etiquetas, establecí el texto y etc. mi problema es obtener esa vista en la celda de vista de tabla pero no esas etiquetas.Adición de etiquetas Como subvista a 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]; 

esto es sólo YO SOY marco, texto para sellos como que se ocultaba en una 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]; 

y aquí estoy agregando que UIView a un cell.and tableview no sé cómo agrega esas etiquetas a mi UIView. por favor, ayúdame.

lo siento si hay algún error en inglés. alguien por favor ayúdame. muchas gracias de antemano.

+0

¿Puede compartir el código donde está agregando las etiquetas a UIView? –

+0

Agregue estas líneas, [self.contentView addSubview: countLabel]; [self.contentView addSubview: hrsLabel]; –

+0

¿Este código está en una clase de celda separada ?. Si es así, debe asignar las etiquetas. –

Respuesta

2

Añadir las etiquetas para GreeView como este,

Ej:

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 esto le ayudará.

+0

Creo que esto es para agregar etiquetas a tableviewCell.i necesito agregar etiquetas a la vista que está presente en tableviewCell .. –

+0

Sí. Voy a actualizar. –

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 estoy de acuerdo con su respuesta. Pero creé esa vista como Objective-C con la subclase de UIView.So en el archivo .m no obtengo el método [myView addSubView:] aquí lo tengo ahora.como acabo de agregar como [self addSubview: countLbl] y gracias por su respuesta –

3

crear etiquetas como etiqueta y label1 y añadir en 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

aquí SubView debe ser Subvista Creo –

+0

sí Gracias 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]; 

fin tengo mi respuesta como anteriormente. Muchas gracias por todas nuestras respuestas.

Cuestiones relacionadas