2012-08-22 15 views
5

qualcuno può dirmi come aggiungere due etichette per una vista che sono stato aggiunto su UITableView Cell.i ho creato quella vista come UIView con qualche nome.e ho creato due etichette nella classe UIView e imposta anche il frame per le etichette, imposta il testo e il problema ecc. Il mio problema è ottenere quella vista nella cella tableview ma non quelle etichette.Aggiunta di etichette come sottoview 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]; 

questo è solo io pongo cornice, testo per etichette come che in un 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]; 

e qui sto aggiungendo che UIView a un cell.and Tableview io non so come aggiungi queste etichette al mio UIView. mi aiuti per favore.

scusa se qualche errore in inglese. per favore qualcuno mi aiuti. grazie mille in anticipo.

+0

Puoi condividere il codice in cui aggiungi le etichette a UIView? –

+0

Aggiungi queste righe, [self.contentView addSubview: countLabel]; [self.contentView addSubview: hrsLabel]; –

+0

Questo codice è in una classe di celle separata ?. Se è così, è necessario assegnare le etichette. –

risposta

2

Aggiungere le etichette per GreeView come questo,

Esempio:

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

Spero che questo vi aiuterà.

+0

Penso che questo sia per aggiungere un'etichetta a tableviewCell.i bisogno di aggiungere etichette sulla vista che è presente in tableviewCell .. –

+0

Sì. Aggiornerò –

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

sì @ Rupesh.i sono d'accordo con la tua answer.but ho creato quella vista come Objective-C con sottoclasse di UIView.So nel file .m sto non ottenendo [myView addSubView:] metodo qui ho capito ora.come aggiungo appena come [self addSubview: countLbl] e grazie per la tua risposta –

3

creare etichette come etichetta e label1 e aggiungere in 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

qui SubView dovrebbe essere Subview Penso che –

+0

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

Infine ho avuto la mia risposta come sopra. Grazie mille per tutte le tue risposte.

Problemi correlati