J'ai un sous-classé UIAlertView comme suit:UIAlertView pas sous-classé dessiné correctement dans iOS 4.2
@interface NarrationAlertView : UIAlertView {
UIImage * backgroundImage; //The image I want as custom background
UILabel * textualNarrationView; //The test I wanna be displayed on the view
}
et mis en œuvre ainsi:
- (id)initNarrationViewWithImage:(UIImage *)image{
if (self = [super init]){
UILabel * alertTextLabel = [[UILabel alloc] initWithFrame:CGRectZero];
self.textualNarrationView = alertTextLabel;
[alertTextLabel release];
[self addSubview:alertTextLabel];
}
return self;
}
- (void)drawRect:(CGRect)rect {
/* Here I draw the image as background */
CGSize imageSize = self.backgroundImage.size;
[self.backgroundImage drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)];
}
- (void)layoutSubviews {
/* To fit the text */
[textualNarrationView sizeToFit];
CGRect textRect = textualNarrationView.frame;
textRect.origin.x = (CGRectGetWidth(self.bounds) - CGRectGetWidth(textRect))/2;
textRect.origin.y = (CGRectGetHeight(self.bounds) - CGRectGetHeight(textRect))/2;
textRect.origin.y -= 70;
textualNarrationView.frame = textRect;
}
- (void)show{
/* Showing the view */
[super show];
CGSize imageSize = self.backgroundImage.size;
self.bounds = CGRectMake(0, 0, imageSize.width, imageSize.height);
}
Sur les versions précédentes d'iOS (je suis toujours en testant sur le simulateur) la sous-classe fonctionne bien et lorsqu'elle est montrée, elle affiche l'image d'arrière-plan personnalisée dessinée correctement et juste le texte dessus, alors que dans la version 4.2 elle dessine l'arrière-plan classique UIAlertView (le rectangle arrondi aux coins bleus) sur le dessus de mon image.
Qu'est-ce que je fais mal? Toute suggestion concernant la programmation UIAlertView et UIView sera également appréciée.
MISE À JOUR Est-ce que quelqu'un a eu une classe de remplacement UIAlertView à partager?
je craignais que, comment avez-vous accompli l'effet pop-up combiné avec la vue ombrée de fond? – rano
En fait, nous sommes allés différemment avec l'interface utilisateur, ce qui était auparavant une fenêtre déroulante glisse vers le bas/glisse du haut de l'écran. J'ai cherché à reproduire l'effet pop-up, et j'ai trouvé ce lien utile: http: //delackner.com/blog/2009/12/mimicking-uialertviews-animated-transition/ –
Ty Je vais y jeter un coup d'œil – rano