iOS开发中在加载页面添加菊花动画(非第三方)

环境:系统版本:OSX 10.10.2Xcodel版本:6.3.2 模拟器:iPhone6   其他:使用MRC

功能:在加载页面添加菊花动画

1.新建一个类MyActivityIndicatorView,继承于UIActivityIndicatorView,添加初始化方法

先定义宏(模拟器为iPhone6)

#define kWidth 375
#define KHeight 667
#define MYCOLOR [UIColor blackColor]

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 菊花背景的大小
        self.frame = CGRectMake(kWidth/2-50, KHeight/2-50, 100, 100);
        // 菊花的背景色
        self.backgroundColor = MYCOLOR;
        self.layer.cornerRadius = 10;
        // 菊花的颜色和格式(白色、白色大、灰色)
        self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
        // 在菊花下面添加文字
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 60, 80, 40)];
        label.text = @"loading...";
        label.font = [UIFont systemFontOfSize:14];
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor whiteColor];
        [self addSubview:label];
    }
    return  self;
}


2.在加载网络之前调用该方法

// 自带菊花方法
    self.myActivityIndicatorView = [[MyActivityIndicatorView alloc]init];
    [self.view addSubview:_myActivityIndicatorView];
    // 动画开始
    [_myActivityIndicatorView startAnimating];

3.网络请求完成,数据加载后调用取消动画方法

// 动画结束
    [_myActivityIndicatorView stopAnimating];



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值