2011-04-06 62 views
0

我正在處理待辦事項列表應用程序。但是,我似乎無法正確地將我的複選框圖像與cell.textLabel.text對齊。UITableViewCell文本對齊和子視圖重疊

我對下面的代碼問題的話「考試考試」通過我的複選框圖像,只留下了「t檢驗」了蓋

我的複選框按鈕圖像像

UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(5.0, 7.0, 25.0, 25.0)]; 

UIImage *uncheckedButtonImage = [UIImage imageNamed:@"unchecked_checkbox.png"]; 

[button setImage:uncheckedButtonImage forState:UIControlStateNormal]; 

[cell.contentView addSubview:button]; 
代碼

和我的手機爲textLabel只是

cell.textLabel.text = @"test test"; 

反正是有對齊的爲textLabel文字有點向右移動?

+0

爲什麼不使用UILabel作爲視圖並將其添加到單元格,您將擁有更多的控制權。 – 2011-04-06 14:53:57

回答

0

最簡單的解決方案是查看UITableViewCell的「縮進」屬性。有關更多信息,請參閱文檔。子類化單元格並添加自己的UILabel會給你最多的控制。

1

我建議添加UILabel,因爲在未來,如果您需要更改視圖單元格,它將更加動態,並且可以更輕鬆地播放任何新的單元格。

看看下面的代碼片段:

CGRect DeviceNameFrame = CGRectMake(101, 32, 522, 21); 

    UILabel *lblDeviceName = [[UILabel alloc] initWithFrame:DeviceNameFrame]; 
    lblDeviceName.backgroundColor = [UIColor clearColor]; 
    lblDeviceName.font = [UIFont fontWithName:@"Helvetica-Bold" size:17]; 
    lblDeviceName.text = @"test test"; 
    lblDeviceName.lineBreakMode = UILineBreakModeMiddleTruncation; 
    [cell.contentView addSubview:lblDeviceName]; 
    [lblDeviceName release]; 

我希望這會幫助你。

+0

嗨艾哈邁德,如果我使用這種解決方案,那麼當我「刷卡刪除」,刪除按鈕將與uitableviewcell中的文本重疊。你知道這個解決方法嗎? – lucas 2011-04-06 15:08:06

+0

@lucas:你想讓UILabel在滑動時超過刪除按鈕嗎? – 2011-04-06 16:21:03