ios - uilabel 上的罢工消失在 uitableview 中是否选择了单元格

标签 ios uikit uilabel uitableview

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

最佳答案

尝试将删除线直接添加到带有文本 (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];

关于ios - uilabel 上的罢工消失在 uitableview 中是否选择了单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12300211/

相关文章:

ios - SecTrustEvaluate 总是返回 kSecTrustResultRecoverableTrustFailure 和 SecPolicyCreateSSL

ios - 从外部 URL 加载方法后继续加载 View

iphone - UIScrollView中UITableView的教程或示例代码

iOS:单个字符的 sizeWithFont 与字符串不同?

ios - 如何使用 Swift 选择器?选择器不断将结果变为 `Type has no member`

ios - 在 viewDidLoad 中确定框架/边界

iphone - 有人知道纯 UIKit 游戏源码吗?

objective-c - 快速滚动时未调用 UIScrollView scrollViewDidEndDragging

ios - 自动布局 - 将一个 UILabel 的原点替换为另一个

ios - UILabel 以编程方式添加,在 iphone 6 上显示模糊文本