当前位置:网站首页>[oc]- < getting started with UI> -- common controls - prompt dialog box and wait for the prompt (circle)

[oc]- < getting started with UI> -- common controls - prompt dialog box and wait for the prompt (circle)

2022-07-06 08:58:00 About Xiaosi

UIAlertController

 UIAlertController yes iOSUI Waiting prompt box control of the interface 

Be careful

  • stay iOS 9.0 after The previous prompt dialog UIAlertView deprecated
    When we play UIAlertView When the object
     Insert picture description here
  • It also includes some video explanations Xcode The compilation environment of has become iOS 9 following
  • stay iOS 9 after Xcode A new UIAlertController Object to create a dialog prompt box object

UIAlertController Usage of

  • Create a warning prompt box object
  • Develop a method of synthesizing access methods [email protected]
@interface ViewController : UIViewController<UIAlertViewDelegate> {
    
    //  Warning box view object 

    UIAlertController* _alertView ;
    //  Wait for the prompt object 
    // Display this control when downloading or loading large files , In the state of waiting for promotion 
}
@property(retain, nonatomic)   UIAlertController*  alertView;
@end

  • Synchronize attributes and member variables
@implementation ViewController//  Implementation part 

@synthesize alertView = _alertView;
//  Wait for the prompt box   Not here 
@synthesize activityIndicator = _activityIndicator;
  • Add one more button Use the same event function
    Circular creation It can be created separately
  • The reason why the loop is created is that I put Prompt dialog And Wait for the prompt The two buttons together create
  • Button to create another blog UIBUtton The creation of
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        
        btn.frame = CGRectMake(100, 100 + 100 * i, 100, 40);
[btn setTitle:@" Warning dialog frame " forState:UIControlStateNormal];

//  Because I create loops   Set the sign   in order to button  Reference to the event 
 btn.tag = 100 + i
  • add to button event function
  • The reason for taking parameters is that we have more than one button
 [btn addTarget:self action:@selector(pressBtn :) 
 forControlEvents:UIControlEventTouchUpInside];

iOS9.0. above UIAlertController Create method

  • 1) iOS 9 After that UIAlertController usage
    The topic and content of the prompt :
 _alertView = [UIAlertController alertControllerWithTitle:@" Warning " 
 message:@" My mobile phone was invaded by me , About to shut down , Hit the money quickly " 
 preferredStyle:UIAlertControllerStyleAlert];
  Parameters 1: Warning    -- Is the title of our prompt box 
  Parameters 2: My mobile phone was invaded by me , About to shut down , Hit the money quickly " --- Prompt content 
  • 2) Add options
    • Option one :
  UIAlertAction* sure = [UIAlertAction actionWithTitle:@" determine " 
  style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action)
   {
    
            NSLog(@" determine ");
        }];
  • Option 2 —cancle
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@" Cancel " 
style:UIAlertActionStyleCancel handler:nil];
  • 3) Add options to the view _alertView
    • _alertView Is the prompt box view we created
   [_alertView addAction:sure];
   [_alertView addAction:cancel];
        
  • Show view
//  Show view 
        [self presentViewController:_alertView animated:YES 
        completion:nil];
        

effect

 Insert picture description here

UIActivityIndicatorView

  • Wait for the prompt object -- Display this control when downloading or loading large files , In the state of waiting for promotion
//  Wait for the prompt object 
    // Display this control when downloading or loading large files , In the state of waiting for promotion 
    UIActivityIndicatorView* _activityIndicator;

UIActivityIndicatorView The creation of

  • Synthetic access methods
@property(retain, nonatomic)   UIActivityIndicatorView* activityIndicator;
  • Synchronize attributes and member variables
@synthesize activityIndicator = _activityIndicator;
  • establish button
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        
 btn.frame = CGRectMake(100, 100 + 100 * i, 100, 40);

 [btn setTitle:@" Prompt dialog " forState:UIControlStateNormal];
   btn.tag = 100 + i;
        
        [btn addTarget:self action:@selector(pressBtn :) forControlEvents:UIControlEventTouchUpInside];
        
        [self.view addSubview:btn];

        
  • add to button event
    • Wait for the indicator wide High is unchangeable
    _activityIndicator = [[UIActivityIndicatorView alloc]
     initWithFrame:CGRectMake(100, 300, 80, 80)] ;
  • Wait for the indicator to turn into what color
self.view .backgroundColor = [UIColor whiteColor];
[self.view addSubview:_activityIndicator];
        
  // Start the animated screen display 
 [_activityIndicator startAnimating];

effect

 Insert picture description here

  • When we click the prompt dialog The circles in the figure will appear

Wait for the deactivation of the dialog box

When we don't need this effect , Enter this line of code to not display the animation

 // Stop waiting for dialog 
 [_activityIndicator stopAnimating];
原网站

版权声明
本文为[About Xiaosi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060850138874.html