5

UITableViewに追加されたビューに2つのラベルを追加する方法を教えてもらえますかCell.iはそのビューをUIViewとして名前を付けて作成しました。また、UIViewクラスに2つのラベルを作成し、ラベルのフレームを設定し、テキストを設定し、 etc.myの問題は、テーブルビューセルでそのビューを取得することですが、それらのラベルは取得しません。

    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でフレームやテキストをそのようなラベルに設定しているだけです。

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をテーブルビューセルに追加しています。これらのラベルをUIViewに追加する方法がわかりません。私を助けてください。

英語の間違いがあればごめんなさい。誰か助けてください。よろしくお願いします。

4

4 に答える 4

3

labelや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];
于 2012-08-22T12:30:59.650 に答える
2

このようにGreeViewにラベルを追加します。

例えば:

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

これがお役に立てば幸いです。

于 2012-08-22T11:45:02.313 に答える
2
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;
于 2012-08-22T11:59:04.090 に答える
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];

最後に私は上記のように私の答えを得ました。すべてのurの返信に感謝します。

于 2012-08-22T12:45:11.850 に答える