iOS開發(fā)中在加載頁面添加菊花動(dòng)畫(非第三方)

1.新建一個(gè)類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.在加載網(wǎng)絡(luò)之前調(diào)用該方法

// 自帶菊花方法

? ? self.myActivityIndicatorView = [[MyActivityIndicatorView alloc]init];

? ? [self.view addSubview:_myActivityIndicatorView];

? ? // 動(dòng)畫開始

? ? [_myActivityIndicatorView startAnimating];

3.網(wǎng)絡(luò)請(qǐng)求完成,數(shù)據(jù)加載后調(diào)用取消動(dòng)畫方法

// 動(dòng)畫結(jié)束

? ? [_myActivityIndicatorView stopAnimating];

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容