UIAlertController的常用方法,属性

示例代码

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void) createImageBtn
{
    //这是初始化
    UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)];

    //这才是设置图片
   [imageView setImage:[UIImage imageNamed:@"7.jpg"]];
    //UIImage* icon02 = [UIImage imageNamed:@"7.jpg"];

    imageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"3.jpg"], [UIImage imageNamed:@"2.jpg"],[UIImage imageNamed:@"7.jpg"], nil];

    imageView.animationDuration = 0.3f; // 设置循环一次的时间

    imageView.animationRepeatCount = 0; // 循环的次数。设置为0时无限循环

    [imageView startAnimating]; // 开始动画

    // [oneImageView stopAnimating]; // 停止动画



    [self.view addSubview:imageView];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    [self createImageBtn];

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void) createBtn
{
    UIButton* btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    UIButton* btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    btn.tag = 100;
    btn1.tag = 101;

    btn.frame = CGRectMake(100, 100, 80, 40);

    [btn setTitle:@"按钮" forState:UIControlStateNormal];

    btn.frame = CGRectMake(100, 140, 80, 40);

    [btn setTitle:@"按钮" forState:UIControlStateNormal];

    [btn addTarget:self action:@selector(showSheet) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:btn];
}

- (IBAction)showAlert:(UIButton*)sender
{
    UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"注册" message:@"表面注册了解一下" preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction* yes = [UIAlertAction actionWithTitle:@"返回" style:UIAlertActionStyleDefault handler:nil];

    UIAlertAction* no = [UIAlertAction actionWithTitle:@"返回" style:UIAlertActionStyleDestructive handler:nil];

//    UIAlertAction* no1 = [UIAlertAction actionWithTitle:@"返回" style:UIAlertActionStyleDestructive handler:nil];

    [alert addAction:yes];

    [alert addAction:no];

    [self presentViewController:alert animated:YES completion:nil];

}

- (IBAction)showSheet:(UIButton* )sender
{
    //
    UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"1" message:@"2" preferredStyle:UIAlertControllerStyleActionSheet];

    UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"3" style:UIAlertActionStyleCancel handler:nil];

    UIAlertAction* deleteAction = [UIAlertAction actionWithTitle:@"4" style:UIAlertActionStyleDestructive handler:nil];

    UIAlertAction* apple = [UIAlertAction actionWithTitle:@"5" style:UIAlertActionStyleDefault handler:nil];

    UIAlertAction* banana = [UIAlertAction actionWithTitle:@"6" style:UIAlertActionStyleDefault handler:nil];

    [alert addAction:cancelAction];

    [alert addAction:apple];

    [alert addAction:banana];

    [alert addAction:deleteAction];

    [alert presentViewController:alert animated:YES completion:nil];






}


- (void) pressBtn:(UIButton* ) btn
{
    if (btn.tag == 100) {
        [self showSheet:btn];
    }
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    [self createBtn];

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

心得体会

  1. 记住要把他放到屏幕上

猜你喜欢

转载自blog.csdn.net/KevinAshen/article/details/81170315