2012-09-06 107 views
0

1)我想創建一個striked文本,所以我已經使用了ext框架,我已經創建它,並保持它的工作正常,當我在表中使用它時當我選擇單元格中的標籤上的罷工細胞disaperared罷工uilabel消失在uitableview沒有選擇單元格

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

這裏我還沒有作爲背景顏色的標籤。我們如何創建一個應該是動態的罷工類型的文本 – 08442

回答

1

嘗試直接添加刪除線與文本(price1_lbl)的標籤。如果這不起作用,你可以試試this lib


UPDATE:

您可以使用此代碼:

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

Hoe添加它與文本mr.luders先生 – 08442

+0

[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 –

+0

在這裏我正在作爲背景顏色。我怎樣才能正確地在xact文本先生pls .. – 08442

相關問題