taille de la police UITableViewCell ne change pas
-
10-10-2019 - |
Question
Je suis en train d'obtenir la taille de la police sur mon UITableViewCell être plus petit. Voici le code que j'ai:
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString* CellIdentifier = @"Cell";
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
UILabel *nameLabel;
UISwitch *mySwitch;
if ( cell == nil )
{
cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault
reuseIdentifier: CellIdentifier] autorelease];
nameLabel = [[[UILabel alloc] initWithFrame:CGRectMake( 220, 13, 100, 20 )] autorelease];
nameLabel.tag = 22;
nameLabel.font = [UIFont boldSystemFontOfSize: 5.0];
nameLabel.textColor = [UIColor blueColor];
nameLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
nameLabel.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview: nameLabel];
mySwitch = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
mySwitch.tag = ((400*(indexPath.section+1))+indexPath.row);
[mySwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
[cell addSubview:mySwitch];
cell.accessoryView = mySwitch;
}
else {
nameLabel = (UILabel*)[cell.contentView viewWithTag: 22];
mySwitch = (UISwitch *)[cell.contentView viewWithTag:((400*(indexPath.section+1))+indexPath.row)];
}
nameLabel.textLabel.text = @"Hello";
}
Mais la police de l'étiquette est certainement ne sort pas être la taille 5. de police normale et la taille normale, probablement sur la taille de police 12, ou quelle que soit la valeur par défaut est. Pourquoi ne puis-je changer la taille de la police?
La solution
Essayer cette
Au lieu de nameLabel.textLabel.text = @"Hello";
Utilisez
nameLabel.text = @"Hello";
Autres conseils
Rien à voir avec votre problème, mais il n'y a pas besoin d'ajouter le commutateur en tant que sous-vue. Définition de la vue accessoire devrait ajouter à la cellule et le conserver.
[cell addSubview:mySwitch];
cell.accessoryView = mySwitch;
... devrait juste être ...
[cell setAccessoryView:mySwitch];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow