Artigos com a tag 'UITableViewDelegate'

Personalize as seções em um UITableView Agrupados

potremmo aver necessità di personalizzare la grafica dei titoli delle sezioni, come California o New York dell'esempio qui sotto. Quando usamos um UITableView estilo Grouped podemos precisar para personalizar o layout de títulos das seções, como a Califórnia ou Nova Iorque o exemplo abaixo.

UITableView

Para fazê-lo, por favor use o seguinte código, colocando-a ao delegado, ou seja, a classe que responde ao protocolo UITableViewDelegate :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/ / Eu retornar a minha exibição personalizada, neste caso um objeto
/ Tipo / UILabel
UIView * ) tableView : ( UITableView * ) tableView - (UIView *) tableView: (UITableView *) tableView
NSInteger ) section { viewForHeaderInSection: seção (NSInteger) {

[ [ [ UILabel alloc ] initWithFrame : CGRectZero ] autorelease ] ; UILabel * label = [[[UILabel alloc] initWithFrame: CGRectZero] autorelease];
UIFont boldSystemFontOfSize : 20 ] ; label.font = [UIFont boldSystemFontOfSize: 20];
label.textAlignment = UITextAlignmentCenter;
UIColor blackColor ] ; label.shadowColor = [UIColor blackColor];
1 , 1 ) ; label.shadowOffset CGSizeMake = (1, 1);
"Sezione" ; // Sostituire con un array come al solito Label.Text @ = "Seção", / / Replace com uma matriz, como de costume
UIColor whiteColor ] ; label.textColor = [UIColor whiteColor];
UIColor clearColor ] ; label.backgroundColor = [UIColor clearColor];
; label.opaque = NO;

voltar rótulo;
}
/ / Devemos também apoiar esta mensagem não irá funcionar
CGFloat ) tableView : ( UITableView * ) tableView - (CGFloat) tableView: (UITableView *) tableView
NSInteger ) section { heightForHeaderInSection: seção (NSInteger) {
; voltar 44;
}

É também importante incluir heightForHeaderInSection , não irá funcionar.

Notas de Interesse

o UIImageView , ho utilizzato per inizializzare il frame CGRectZero che corrisponde a CGRectMake(0,0,0,0) . Na criação do nosso UILabel , querendo que também poderia ser um objeto mais complexo, como um UIView ou UIImageView , eu usado para inicializar o frame CGRectZero o que corresponde a CGRectMake(0,0,0,0) .

Leia mais ...


Pare SOPA