Ho un problema davvero strano con UIImageView. Ho un'immagine (una RGB png) 45x45 pixel che aggiungo alla vista. Vedo che l'immagine è sfocata dopo l'aggiunta alla vista. Ecco la stessa immagine nel simulatore (a sinistra) e in Xcode (a destra):Perché la mia UIImageView è sfocata?
alt text http://partywithvika.com/iconinsim.pngalt text http://partywithvika.com/iconinxcode.png
ho lezione UIImageView personalizzato con questo codice initWithImage:
- (id) initWithImage:(UIImage*) image {
self = [super initWithImage:image];
self.frame = CGRectMake(0, 0, 45, 45);
self.contentMode = UIViewContentModeScaleAspectFit;
self.quantity = 1;
if (self) {
self.label = [[UITextField alloc]initWithFrame:CGRectMake(0,40,45,25)];
self.label.font = [UIFont systemFontOfSize:16];
self.label.borderStyle = UITextBorderStyleNone;
self.label.enabled = TRUE;
self.label.userInteractionEnabled = TRUE;
self.label.delegate = self;
self.label.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
self.label.textAlignment = UITextAlignmentCenter;
}
self.userInteractionEnabled = TRUE;
// Prepare 3 buttons: count up, count down, and delete
self.deleteButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.deleteButton.hidden = NO;
self.deleteButton.userInteractionEnabled = YES;
self.deleteButton.titleLabel.font = [UIFont systemFontOfSize:20];
self.deleteButton.titleLabel.textColor = [UIColor redColor];
[self.deleteButton setTitle:@"X" forState:UIControlStateNormal];
[self.deleteButton addTarget:self action:@selector(deleteIcon:) forControlEvents:UIControlEventTouchUpInside];
self.upCountButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.upCountButton.hidden = NO;
self.upCountButton.userInteractionEnabled = YES;
[self.upCountButton setTitle:@"+" forState:UIControlStateNormal];
[self.upCountButton addTarget:self action:@selector(addQuantity:) forControlEvents:UIControlEventTouchUpInside];
self.downCountButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.downCountButton.hidden = YES;
self.downCountButton.userInteractionEnabled = YES;
[self.downCountButton setTitle:@"-" forState:UIControlStateNormal];
[self.downCountButton addTarget:self action:@selector(removeQuantity:) forControlEvents:UIControlEventTouchUpInside];
return self;
}
creo come questo :
UIImage *desertIcon = [UIImage imageNamed:@"desert.png"];
IconObj *desertIconView = [[IconObj alloc] initWithImage:desertIcon];
desertIconView.center = CGPointMake(265,VERTICAL_POINT_ICON);
desertIconView.type = [IconObj TYPE_DESERT];
[self.view addSubview:desertIconView];
[desertIconView release];
Perché l'immagine visualizzata deve essere uguale a quella memorizzata in un file?
Questo è probabilmente correlato al problema, ma il metodo init sarebbe più convenzionale, se, dopo l'assegnazione 'auto = [super initWithImage: Immagine]', si controlla se il sé è pari a zero, e se lo è, torna immediatamente a zero. Se self se mai nullo, è perché (1) l'inizializzatore del genitore non può inizializzarsi correttamente, o (2) alloc restituito nil a causa di alcune strane condizioni di memoria (estremamente rare). È una buona pratica di programmazione difensiva. –
Grazie per la nota, ci proverò. –