1

1)我想创建一个带罢工的文本,所以我使用了 ext 框架,我已经创建了它并保持在 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 回答