Je personnalise une tableview. Je veux cacher la ligne qui se sépare sur la dernière cellule ... puis-je le faire? J'ai vu que c'est une propriété de UITableView mais je voudrais travailler uniquement sur une cellule particulière.
Réponses
Trop de publicités? en viewDidLoad
, ajoutez cette ligne:
self.tableView.separatorColor = [UIColor clearColor];
et en cellForRowAtIndexPath
:
pour les versions inférieures d'iOS
if(indexPath.row != self.newCarArray.count-1){
UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(0, 44, 320, 2)];
line.backgroundColor = [UIColor redColor];
[cell addSubview:line];
}
pour iOS 7 versions supérieures
if (indexPath.row == self.newCarArray.count-1) {
cell.separatorInset = UIEdgeInsetsMake(0.f, 0.f, 0.f, cell.bounds.size.width);
}
À suivre sur Hiren's'réponse.
dans le ViewDidLoad et la ligne suivante :
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
Ou, si vous utilisez XIB ou de story-boards changement "séparateur" à "none" :
Et dans CellForRowAtIndexPath ajouter ceci : CGFloat *separatorInset; // le Séparateur de position x CGFloat *separatorHeight; CGFloat *separatorWidth; CGFloat *ampoule; UIImageView *séparateur UIColor *separatorBGColor;
separatorY = cell.frame.size.height;
separatorHeight = (1.0 / [UIScreen mainScreen].scale); // This assures you to have a 1px line height whatever the screen resolution
separatorWidth = cell.frame.size.width;
separatorInset = 15.0f;
separatorBGColor = [UIColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:1.0];
separator = [[UIImageView alloc] initWithFrame:CGRectMake(separatorInset, separatorY, separatorWidth,separatorHeight)];
separator.backgroundColor = separatorBGColor;
[identityCell separator];
Voici un exemple de résultat lorsque j'affiche une tableview avec la dynamique des Cellules (mais n'avoir qu'un seul avec le contenu). Le résultat étant que seulement que l'on a un séparateur et non pas tout le "dummy" tableview ajoute automatiquement pour remplir l'écran.
Espérons que cette aide.
Dans iOS 7, la UITableView regroupés style, le séparateur de cellules semble un peu différent. Il ressemble un peu à ceci:
J'ai essayé Kemenaran la réponse de le faire:
cell.separatorInset = UIEdgeInsetsMake(0, 10000, 0, 0);
Cependant, cela ne semble pas fonctionner pour moi. Je ne sais pas pourquoi. J'ai donc décidé d'utiliser hiren réponse, mais en utilisant UIView
au lieu de UIImageView
, et trace la ligne de l'iOS 7 style:
if (indexPath.row == 0) {
UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
line.backgroundColor = [UIColor colorWithRed:0.82f green:0.82f blue:0.82f alpha:1.0f];
[cell addSubview:line];
[cell bringSubviewToFront:line];
} else if (indexPath.row == [self.tableViewCellSubtitles count] - 1) {
UIView *line = [[UIView alloc] initWithFrame:CGRectMake(21, 0, 320, 1)];
line.backgroundColor = [UIColor colorWithRed:0.82f green:0.82f blue:0.82f alpha:1.0f];
[cell addSubview:line];
[cell bringSubviewToFront:line];
UIView *lineBottom = [[UIView alloc] initWithFrame:CGRectMake(0, 43, 320, 1)];
lineBottom.backgroundColor = [UIColor colorWithRed:0.82f green:0.82f blue:0.82f alpha:1.0f];
[cell addSubview:lineBottom];
[cell bringSubviewToFront:lineBottom];
} else {
UIView *line = [[UIView alloc] initWithFrame:CGRectMake(21, 0, 320, 1)];
line.backgroundColor = [UIColor colorWithRed:0.82f green:0.82f blue:0.82f alpha:1.0f];
[cell addSubview:line];
[cell bringSubviewToFront:line];
}
Si vous utilisez, assurez-vous de brancher la table correct vue la hauteur dans la seconde si l'instruction. J'espère que cela est utile pour quelqu'un.