使用したい色の割合を計算することができると仮定します。次に、次のように簡単です。
UIView *bg = [[UIView alloc] initWithFrame:frame];
bg.backgroundColor = [UIColor colorWithHue:hue
saturation:percent
brightness:brightness
alpha:1.0];
cell.backgroundView = bg;
正確な目標に応じて、彩度と明るさの組み合わせを使用して遊んでみたいと思うかもしれませんが、色相とアルファは一定です。
編集:
リンクに表示されているように、背景を棒グラフにしたい場合は、もう少し複雑な背景ビューを作成する必要があります。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * const CellIdentifier = @"MyCellIdentifier";
static const NSInteger BarTag = 0xBEEF;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier
forIndexPath:indexPath];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
UIView *background = [[UIView alloc] initWithFrame:cell.bounds];
background.autoresizeMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
UIView *bar = [[UIView alloc] initWithFrame:cell.bounds];
bar.autoresizeMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin;
bar.tag = BarTag;
bar.backgroundColor = [UIColor redColor];
[background addSubView:bar];
cell.backgroundView = background;
}
CGFloat percent = .5; // Calculate this somehow
UIView *backgroundBar = [cell.backgroundView viewWithTag:BarTag];
CGFrame frame = backgroundBar.frame;
frame.size.width = CGRectGetWidth(tableView.frame) * percent;
backgroundBar.frame = frame;
return cell;
}