【问题标题】:strike on the uilabel disappears in uitableview did select celluilabel 上的罢工在 uitableview 中消失了选择单元格
【发布时间】:2012-09-06 12:32:29
【问题描述】:

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

【问题讨论】:

  • 这里我已经将标签的背景颜色作为背景颜色。我们如何创建应该是动态的罢工类型文本

标签: ios uikit uilabel uitableview


【解决方案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];

【讨论】:

  • 锄头添加文本 mr.luders 先生
  • [price1_lbl addSubview: lineLabel];但一定要正确设置线标的边框为: origin.x = 0.0f ; origin.y = price1._lbl.frame.size.height / 2.0f ; size.width = price1._lbl.frame.size.width; size.height = 1.0f
  • 这里我将其作为背景颜色。先生,我怎样才能在 xact 文本上正确制作..
  • 这里我将其作为背景色。先生,我怎样才能在 xact 文本上正确制作 .. 我没有添加线条,它是标签的背景颜色
  • 您不能将删除线文本明确设置为 UILabel。你必须用一种解决方法来做到这一点......对不起,如果我真的不明白你的问题
猜你喜欢
  • 1970-01-01
  • 2013-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-27
  • 2012-03-17
  • 2015-05-06
  • 2021-08-28
相关资源
最近更新 更多