在APP运行中会有一些错误提示,比如输入账号为空、密码错误之类,相信很多人都会选择 UIAlertView 来实现弹窗提示,但是对于一些小错误提示,再使用 UIAlertView 会不会显得有些笨拙了,这个时候有更好的选择 如下图所示的效果相信会更便捷。
首先我们创建文件命名为UILabel+Status.h
随后在需要用到的地方导入头文件#import "UILabel+Status.h"
UILabel+Status.h的 .h文件中
#import <UIKit/UIKit.h>
@interface UILabel (Status)
/**
错误提示框
*/
- (void)showStatusLable:(NSString *)title;
@end
UILabel+Status.h的 .m文件中
#import "UILabel+Status.h"
@implementation UILabel (Status)
- (void)showStatusLable:(NSString *)title
{
self.text = [NSStringstringWithFormat:@"提示:%@", title];//弹出的提示文字
CABasicAnimation* shake = [CABasicAnimationanimationWithKeyPath:@"transform.translation.x"];
shake.fromValue = [NSNumbernumberWithFloat:-5];
shake.toValue = [NSNumbernumberWithFloat:5];
shake.duration =0.1;
shake.autoreverses =YES;
shake.repeatCount =2;
[self.layeraddAnimation:shake forKey:@"shakeAnimation"];
self.alpha =1.0;
self.hidden =NO;
[UIViewanimateWithDuration:3.0delay:0.0options:UIViewAnimationOptionCurveEaseIn |UIViewAnimationOptionAllowUserInteractionanimations:^{
self.alpha =0.0;
} completion:nil];
}
//如果需要调整弹出吐司提示的基本样式,以上属性便可修改
@end
最后在需要用到的地方
.h文件
@property (weak,nonatomic) IBOutletUILabel *tusilabel;
.m文件[self.tusilabelshowStatusLable:@"请输入正确车牌号"];即可