我有一個放置在導航控制器中的表格視圖。表視圖的單元格的寬度小於原始單元格的寬度,而背景是圖像。我怎樣才能設置「選擇的顏色」?這裏是我到目前爲止的代碼:UITableViewCell寬度
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ApplicationCell";
ApplicationCell *cell = (ApplicationCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[CompositeSubviewBasedApplicationCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
return cell;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
{
cellContentView = [[CompositeSubviewBasedApplicationCellContentView alloc] initWithFrame:CGRectInset(self.contentView.bounds, 0.0, 1.0) cell:self];
cellContentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
cellContentView.contentMode = UIViewContentModeRedraw;
//here i'm making the cells smaller in width than the rest of the tableView
CGRect framme = cellContentView.frame;
framme.size.width = framme.size.width-58;
//set the left space
framme.origin.x = framme.origin.x+29;
[cellContentView setFrame:framme];
[self.contentView addSubview:cellContentView];
}
return self;
}
沒問題,但選定的框架不是較小的! – Filip
不,您必須設置一個全尺寸的'selectedBackgroundView',然後像在您的示例中那樣,將子視圖添加到具有適當大小的backgroundView。這也是你應該用'backgroundView'屬性來做的。 –
啊哈,讓我試試看,讓你知道!非常感謝您的幫助 – Filip