我已經嘗試了幾乎所有東西,但我似乎無法將cell.textLabel屬性稍微向下移動。我附上了一張截圖,我已經嘗試了幾乎所有我能找到的東西。我試過修改如果通過使用「 - (void)tableView:(UITableView *)tableView willDisplayCell」方法「修改。我也試過分配一個自定義標籤。可以移動的自定義標籤,但它不會進入不同的線,如原爲textLabel。我只需要移動所描繪的多行標籤有些低落。如何更改單元格的textLabel框架?
任何幫助表示讚賞!
我已經嘗試了幾乎所有東西,但我似乎無法將cell.textLabel屬性稍微向下移動。我附上了一張截圖,我已經嘗試了幾乎所有我能找到的東西。我試過修改如果通過使用「 - (void)tableView:(UITableView *)tableView willDisplayCell」方法「修改。我也試過分配一個自定義標籤。可以移動的自定義標籤,但它不會進入不同的線,如原爲textLabel。我只需要移動所描繪的多行標籤有些低落。如何更改單元格的textLabel框架?
任何幫助表示讚賞!
要做到這一點的唯一方法是使用UITableViewCell
子類並覆蓋-layoutSubviews
。在這種方法中,您需要撥打[super layoutSubviews]
,然後對標籤進行任何幀調整。
我最終在字符串的開頭添加了一個\ n。不幸的是我無法得到任何其他工作。
覆蓋layoutSubviews
您UITableViewCell
...
- (void)layoutSubviews {
[super layoutSubviews];
CGSize size = self.bounds.size;
CGRect frame = CGRectMake(4.0f, 4.0f, size.width, size.height);
self.textLabel.frame = frame;
self.textLabel.contentMode = UIViewContentModeScaleAspectFit;
}
,或者你可以簡單地使自己的UILabel對象,並將其添加到cell.contentView作爲一個子視圖。
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(4, 4, 30, 30)];
[cell.contentView addSubview:label];
[label release];
- (void)layoutSubviews {
[super layoutSubviews];
CGSize size = self.bounds.size;
CGRect frame = CGRectMake(4.0f, 4.0f, size.width, size.height);
self.textLabel.frame = frame;
self.textLabel.textAlignment = NSTextAlignmentCenter;
}
你能解釋一下你的代碼做了什麼,以及爲什麼它回答了這個問題? – Mel 2015-12-16 10:42:50