IOS开发-07.自定义HUD(提示框)

来源:互联网 发布:消除噪音软件 编辑:程序博客网 时间:2024/05/17 02:42

1. 自定义HUD概述

  • 在系统自带的框架或者类不满足我们开发需求,或者想制作一个单独的HUD框架时,我们可以自己定义HUD
    -简单效果图
    这里写图片描述

2.代码实现

-(void)touchesBegan:(nonnull NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{    // 1.创建父视图    UIView *hudView = [[UIView alloc] init];    // 2.1设置frame    hudView.bounds = CGRectMake(0, 0, 150, 150);    hudView.center = self.view.center;    // 2.2设置背景颜色    hudView.backgroundColor = [UIColor yellowColor];    // 2.3设置圆角    hudView.layer.cornerRadius = 10.0;    // 3.添加到父视图    [self.view addSubview:hudView];    // 1.创建菊花    UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];    // 2.设置菊花的位置    activity.bounds = CGRectMake(0, 0, hudView.frame.size.width * 2/3, hudView.frame.size.height * 2/3);    activity.center = CGPointMake(hudView.frame.size.width/2, hudView.frame.size.height * 1/3);    // 3.设置菊花转动    activity.color = [UIColor redColor];    [activity startAnimating];    // 3.添加到父视图    [hudView addSubview:activity];    // 1.创建文本    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,CGRectGetMaxY(activity.frame), hudView.frame.size.width, hudView.frame.size.height * 1/3)];    // 2.设置文本内容    label.text = @"正在拼命加载...";    label.textAlignment = NSTextAlignmentCenter;    // 3.设置背景颜色    label.textColor = [UIColor blackColor];    // 4.添加到视图    [hudView addSubview:label];}
0 0
原创粉丝点击