Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pop-up for 1 second [closed]

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).

like image 798
Ilan Avatar asked Aug 27 '13 21:08

Ilan


1 Answers

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.

like image 172
i_am_jorf Avatar answered Nov 07 '22 12:11

i_am_jorf