Friday, 4 April 2014

Show PopUp Message on the Place of UIAlertView

+(void)showPopUpWithMessage:(NSString *)message inController:(UIViewController *)controller
{
    
    CGFloat width =  [message sizeWithFont:[UIFont systemFontOfSize:20.0f ]].width;
    
    UIView *alertView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, width+10, 40)];
    [alertView setBackgroundColor:[UIColor redColor]];
    
    [alertView setCenter:CGPointMake( controller.view.bounds.size.width / 2, (controller.view.bounds.size.height-40) / 2)];
    
    [alertView.layer setCornerRadius5.0f];
    [alertView.layer setBorderWidth: 2.0f];
    [alertView.layer setMasksToBounds: YES];
    
    
    
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(5, 10, width, 20)];
    [label setBackgroundColor:[UIColor clearColor]];
    [label setBaselineAdjustment:UIBaselineAdjustmentAlignCenters];
    [label setFont:[UIFont systemFontOfSize:20.0f]];
    [label setTextAlignment:NSTextAlignmentCenter];
    [label setTextColor:[UIColor whiteColor]];
    
    [label setText:message];
    
    [alertView addSubview:label];
    
    [controller.view addSubview:alertView];
    
    [UIView animateWithDuration:5.0
                     animations:^  {alertView.alpha = 0; }
                     completion:^ (BOOL finished) { [alertView removeFromSuperview]; }];
    

}

No comments:

Post a Comment