2012-08-22 2 views
5

может кто-нибудь сказать мне, как добавить две метки для представления, которое было добавлено в UITableView Cell.i, создали это представление как UIView с некоторым именем. И я создал две метки в классе UIView и также установите рамки для меток, задайте текст и т. д. Моя проблема заключается в том, что я получаю этот вид в ячейке tableview, но не с этими ярлыками.Добавление ярлыков Поскольку subview для 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 к Tableview cell.and я не знаю, как добавьте эти ярлыки в мой UIView. пожалуйста помогите.

извините, если возникнут ошибки на английском языке. кто-нибудь, пожалуйста, помогите мне. спасибо за много заранее.

+0

Можете ли вы поделиться кодом, в котором вы добавляете метки в UIView? –

+0

Добавьте эти строки, [self.contentView addSubview: countLabel]; [self.contentView addSubview: hrsLabel]; –

+0

Этот код в отдельном классе ячейки ?. Если это так, вам нужно выделить метки. –

ответ

2

Добавьте метки для GreeView как это,

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

Надеется, что это поможет.

+0

Я думаю, что это добавить ярлык в tableviewCell.i нужно добавить ярлыки на просмотр, который присутствует в tableviewCell .. –

+0

Yep. Я обновлю. –

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 согласен с вашим ответом. Но я создал это представление как Objective-C с подклассом UIView.So в .m файле, не получая метод [myView addSubView:], здесь я получил его сейчас.как я просто добавлю, как [self 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

здесь SubView должен быть Subview Думаю –

+0

yeah Спасибо 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]; 

Наконец я получил мой ответ, как описано выше. Большое спасибо за все ответы ур.

Смежные вопросы