2013-06-26 40 views

回答

1

你可以做到這兩種方式。

  1. 創建自定義標籤並設置其框架。

    UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)]; 
    [cell.contentView addSubView:lbl]; 
    
  2. 使用UITableViewCell子類並覆蓋-layoutSubviews。在這種方法中,您需要致電[super layoutSubviews]

    - (void)layoutSubviews { 
        [super layoutSubviews]; 
    
        CGSize size = self.bounds.size; 
        CGRect frame = CGRectMake(0.0f, 0.0f, size.width, size.height); 
        self.textLabel.frame = frame; 
        self.textLabel.contentMode = UIViewContentModeScaleAspectFit; 
    } 
    
+0

偉大的你已經說過在我之前完全相同的答案:) – NightFury

0

設置autolayout頂部屬性UILabel

1

寫下面的代碼:

UILabel *myLable = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, width, height)]; 
[cell.contentView addSubView: myLable]; 

如果你也想myLable FRAM是similare到myLable.text然後寫..

[myLable sizeToFit]; 
1

,因爲它是自動調整,你不能改變的textlabel位置。

第一個選項是您需要繼承UITableViewCell並自定義textLabel框架。

另一個是你創建自己的自定義標籤並使文本標籤爲零。所以每當細胞高度發生變化時,您的標籤位置不會改變。

0

試試這個:

設置假以 「自動調整子視圖」 自定義單元格的屬性...

2

雖然分配的UITableViewCell,你需要做這樣的..

UITableViewCell * cell; 

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:string]; 

在用樣式:UITableViewCellStyleSubtitle進行初始化的時間即將到來。

希望這會起作用..

相關問題