Search code examples
iosobjective-cuiactionsheetuiactivityindicatorview

Add UIActivityIndicatorView to UIActionSheet


I am trying to add an UIActivityIndicatorView to UIActionsSheet in this way:

UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                  initWithTitle:nil
                                  delegate:sharedInstance
                                  cancelButtonTitle:nil
                                  destructiveButtonTitle:nil
                                  otherButtonTitles:nil];

for(NSMutableDictionary *dict in moreStructure)
   {
       NSString *value = [dict valueForKey:TITLE_PARAMETER];
       [actionSheet addButtonWithTitle:value];
   }
    [actionSheet addButtonWithTitle:@"Cancel"];
    actionSheet.cancelButtonIndex = [moreStructure count];
    [actionSheet showInView:((SectionViewController *)sharedInstance.currentViewController).view];
    UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    activityView.frame = CGRectMake(100, 500, 15, 15);
    [activityView startAnimating];
    [actionSheet addSubview:activityView];

When the UIActionSheet appears, however, I do not see an UIActivityIndicatorView on it. Please, help me.


Solution

  • I have try this and this is working... Please check frame of activityView... because its y is 500...

    UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                      initWithTitle:nil
                                      delegate:nil
                                      cancelButtonTitle:@"Test"
                                      destructiveButtonTitle:@"Test"
                                      otherButtonTitles:nil];
    
        [actionSheet showInView:self.view];
    
        UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        activityView.frame = CGRectMake(100, 5, 15, 15);
        [activityView startAnimating];
        [actionSheet addSubview:activityView];
    
        activityView.backgroundColor = [UIColor redColor];
        actionSheet.backgroundColor = [UIColor greenColor];