質問

tableviewcell のさまざまな backgroundColor colorwithPatternImage で指定しようとしていますが、期待どおりに機能しません。ドキュメントには、一度に1つのパターンしか使用できないことについては何も記載されていません。

3行あるとし、背景を次のように設定します:

Cell1.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"red.png"]];

Cell2.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"green.png"]];

Cell3.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"blue.png"]];

3行すべてが赤になります。返されるグローバルカラーがあるかのようです。

colorWithPatternImage は、渡される画像に関係なく、呼び出しごとに kCGColorSpaceModelPattern 1 を返します。一度に1つのグローバルパターンしか持っていない場合は、色最後のセット、つまり青にする必要があります。

これは意味がありません。 Appleがここで行っていることについて、専門知識を持っている人はいますか?

編集 まったく別のビューで別のパターンを使用しても、他のビューのパターンに影響します。ドキュメントにはこれが記載されていませんが、一度に1つのUIColorイメージパターンに制限されていると確信しています。悲しい。

役に立ちましたか?

解決

これまでのところ、これは事実ではないか、事実ではありません。ここにいくつかのUITableViewCellsがあり、それぞれが異なるbackgroundImageを持ち、問題なく動作します。

他のヒント

Cell1とは何ですか?これらをどこで(どのような方法で)設定していますか?

私はあなたがこれをすべて行うべきだと言うでしょう

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    MyTableCell *cell = (MyTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {      
      // create cell
    }

    // Set up the cell...

    // set up a background color
    if (something)
        cell.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"red.png"]];
    else (another)
        cell.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"green.png"]];
    else
        cell.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"blue.png"]];
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top