iOS开发之类似Android中Toast效果制作

时间:2023-02-08 22:10:45

ios中没有类似于Androidtoast效果的提示,在提示用户的时候显得尤为不便,因此做了一个类似Toast的功能.

UILabel *hintLabel = [[UILabel alloc] initWithFrame:CGRect(80,400,160,40)];

hintLabel.textAlignment = NSTextAlignmentCenter;

hintLabel.backgroundColor = [UIColor lightGrayColor];

hintLabel.alpha = 0.0;

hintLabel.text = @"提示字符...........";

[self.view addSubview:hintLabel];

//animateWithDuration可以控制label显示持续时间

[UIView animateWithDuration:1.0 animations:^{

hintLabel.alpha = 1.0;

} completion:^(BOOL finished){

[hintLabel removeFromSuperview];

}];