Trzeba zmienić kolor zaznaczenia widoku tabeli

Muszę zmienić domyślny niebieski kolor wyboru widoku tabeli na jakiś niestandardowy kolor. Jest na to jakiś sposób. Help me

Author: Charles Sprayberry, 2009-09-28

5 answers

Najlepszy sposób na to jest tak:

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"myCellId";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        UIView *v = [[[UIView alloc] init] autorelease];
        v.backgroundColor = [UIColor redColor];
        cell.selectedBackgroundView = v;
    }
    // Set up the cell...
    cell.textLabel.text = @"foo";
    return cell;
}

Odpowiednią dla Ciebie częścią jest cell.selectedBackgroundView = v; Instrukcja. Możesz zastąpić podstawowy widok 'v' dowolnym widokiem, który Ci się podoba.

 62
Author: Zoran Simic,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-09-28 09:34:33

Natknąłem się również na ten problem przy próbie utworzenia niestandardowych widoków wybranych komórek dla zgrupowanej komórki. Rozwiązałem ten problem, tworząc 3 rodzaje obrazów dla górnej, środkowej i dolnej komórki, zakładając, że będzie Środkowa komórka.

NSString *imageFile;

if (row == 0) {
 imageFile = @"highlighted_cell_top.png";
} else if (row == ([registeredDetailsKeys count] - 1)) {
 imageFile = @"highlighted_cell_bottom.png";
} else {
 imageFile = @"highlighted_cell_middle.png";
}

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageFile]];

cell.selectedBackgroundView = imageView;

Jest prawdopodobnie łatwiejszy sposób, ale jestem zadowolony z wyniku.

 6
Author: Ufb007,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-11-25 10:57:41

Nie sądzę, że można użyć niestandardowego koloru. Można jednak użyć następującej właściwości UITableViewCell

@property(nonatomic) UITableViewCellSelectionStyle selectionStyle

Styl zaznaczenia jest stałą widoku tła, która określa kolor komórki, gdy jest zaznaczona. Wartością domyślną jest UITableViewCellSelectionStyleBlue. Od

typedef enum {
   UITableViewCellSelectionStyleNone,
   UITableViewCellSelectionStyleBlue,
   UITableViewCellSelectionStyleGray
} UITableViewCellSelectionStyle;

Możesz przełączyć się z domyślnego niebieskiego na szary lub w ogóle nie wybrać koloru.

 3
Author: Massimo Cafaro,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-09-28 06:56:34

Upewnij się, że po zadeklarowaniu w nagłówku

@property(nonatomic) UITableViewCellSelectionStyle selectionStyle

Zaimplementuj

cell.selectionStyle = UITableViewCellSelectionStyleGray

Gdzie UITableViewCellSelectionStyleGray może być UITableViewCellSelectionStyleNone, UITableViewCellSelectionStyleBlue, UITableViewCellSelectionStyleGray.

 3
Author: dimmalo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-02-10 10:52:03

Innym sposobem na to byłoby przeniesienie nowego widoku na komórkę, z dowolnym kolorem i 50% nieprzezroczystością. Przenieś ten widok na komórkę, gdy otrzymasz-setSelected: animated: call. Kiedy mówię "ruszaj", zawsze możesz mieć widok na swoją komórkę, ale po prostu wyłącz i włącz Ukryty bit, jak potrzebujesz.

 0
Author: mahboudz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-09-28 07:14:24