自定义选择动画提示

本文介绍如何在iOS应用中创建一个用于显示旋转动画的自定义视图,包括背景视图、活动指示器和文本标签的实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#pragma mark - 创建旋转动画提示
- (CustomView *)initIndicatorViewWithTitle:(NSString *)title
{
    self = [super initWithFrame:[[UIScreen mainScreen] bounds]];
    if (self) {
        
        //创建背景视图
        UIView *bgView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
        bgView.alpha = 0.1;//显示此视图时,不可进行其他操作
        bgView.backgroundColor = [UIColor grayColor];
        [self addSubview:bgView];
        
        //创建活动指示器
        UIActivityIndicatorView *indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
        
        CGFloat x = kScreenW / 2 - 50;
        CGFloat y = kScreenH / 2 - 20;
        CGFloat w = 100;
        CGFloat h = 40;
        indicatorView.alpha = 0.5;
        indicatorView.frame = CGRectMake(x, y, w, h);
        
        //设置活动指示器的圆角
        indicatorView.layer.cornerRadius = 4;
        indicatorView.layer.masksToBounds = YES;
        
        //设置活动指示器在自身视图中的位置
        indicatorView.bounds = CGRectMake(25, kZero, 90, h);
        indicatorView.backgroundColor = [UIColor blackColor];
        [indicatorView startAnimating];
        [self addSubview:indicatorView];
        
        //创建显示的文本
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(155, y, w, h)];
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = [UIColor whiteColor];
        label.backgroundColor = [UIColor clearColor];
        [self addSubview:label];
        
        if ([title isEqualToString:@""] || title == nil) {
            label.text = @"加载中";
        }else{
            label.text = title;
        }
    }
    return self;
}
//类方法 + (CustomView *)initIndicatorViewWithTitle:(NSString *)title { return [[self alloc]initIndicatorViewWithTitle:title]; }

 

转载于:https://www.cnblogs.com/hw140430/p/3970380.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值