1

1) 打ち消されたテキストを作成したいので、テキスト フレームを使用し、それを作成して lbal を保持します。セルを選択しているときにテーブル セルで使用すると、ラベルの打ち消しが消えて正常に動作します。

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
}

#pragma mark TableView delegate method.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView1
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView1 numberOfRowsInSection:(NSInteger)section 
{
    return 4;
}

- (CGFloat)tableView:(UITableView *)tableView1 heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 120;
}

- (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:CellIdentifier];
    tableView1.backgroundColor = [UIColor clearColor];
    cell=nil;

    if (cell == nil) 
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;     
        //cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor clearColor];
      //  cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"strip_11C.png"]];
        //cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"strip_11C_h.png"]];

        UILabel *price1_lbl = [[UILabel alloc] initWithFrame:CGRectMake(2,80,100,26)];
        price1_lbl.text = @"label";
        price1_lbl.textColor = [UIColor grayColor];
        price1_lbl.font = [UIFont fontWithName:@"Arial-BoldMT" size:(13.0)];
        price1_lbl.backgroundColor = [UIColor clearColor];

        NSString *string =price1_lbl.text;
        CGSize stringSize = [string sizeWithFont:price1_lbl.font];
        CGRect buttonFrame = price1_lbl.frame;
        CGRect labelFrame = CGRectMake(buttonFrame.origin.x , 
                                       4+buttonFrame.origin.y + stringSize.height/2, 
                                       stringSize.width, 1);

        UILabel *lineLabel = [[UILabel alloc] initWithFrame:labelFrame];
        lineLabel.backgroundColor = [UIColor blackColor];
        [cell.contentView addSubview:price1_lbl];
        [cell.contentView addSubview:lineLabel]; 
    }

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{   
    secondviewcontroller *obj=[[secondviewcontroller alloc]initWithNibName:@"secondviewcontroller" bundle:nil];
    [self.navigationController pushViewController:obj animated:YES];
}
4

1 に答える 1

1

テキスト (price1_lbl) を含むラベルに取り消し線を直接追加してみてください。それでもうまくいかない場合は、このライブラリを試してみてください。


アップデート:

次のコードを使用できます。

CGSize size = [price1_lbl.text sizeWithFont:[UIFont systemFontOfSize:16.0f]];
UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(0 , label.frame.size.height / 2, size.width, 1)];
line.backgroundColor = [UIColor blackColor];
[price1_lbl addSubview:line];
于 2012-09-06T12:49:12.787 に答える