What is the regular (or best) way to implement text+image message to user, while this "alert/pop-up" should appear only for 1 second (like message "You Won!" on Prize picture for limited period of time).
If you just want to show a floating message for a little bit of time and have it fade away, just make a label and a simple animation. This example will show the message for 1 second then fade away over 0.3 seconds (and assumes ARC):
- (void)showMessage:(NSString*)message atPoint:(CGPoint)point {
const CGFloat fontSize = 24; // Or whatever.
UILabel* label = [[UILabel alloc] initWithFrame:CGRectZero];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont fontWithName:@"Helvetica-Bold" size:fontSize]; // Or whatever.
label.text = message;
label.textColor = [UIColor blueColor]; // Or whatever.
[label sizeToFit];
label.center = point;
[self addSubview:label];
[UIView animateWithDuration:0.3 delay:1 options:0 animations:^{
label.alpha = 0;
} completion:^(BOOL finished) {
label.hidden = YES;
[label removeFromSuperview];
}];
}
Just add this as a method on your root view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With