uilabel上的罢工消失在uitableview确实选择了细胞

时间:2012-09-06 12:32:29

标签: ios uikit uilabel uitableview

1)我想创建一个striked文本,所以我使用了这个ext框架,我已经创建了它并保持在lbal它工作正常,当我在表格单元格中使用它时,我选择单元格罢工标签disaperared

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

1 个答案:

答案 0 :(得分:1)

尝试使用文本(price1_lbl)将删除线直接添加到标签。如果这不起作用,您可能需要尝试this lib


<强>更新

您可以使用此代码:

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