iOS 创建语言提示成功后自动消失

来源:互联网 发布:如何做网络推广员 编辑:程序博客网 时间:2024/04/30 17:54

安卓中有个一个类可以简单的进行一个语言提示叫(吐司)

但是iOS没有,但是这个iOS可以通过别的办法来实现

代码如下:


//
成功提示string为提示话语;
主要是下面这个动画,2.f为动画时间,alertLab.alpha = 0.f,意思是指,两秒后alertLab透明度变为0,当然是渐变的过程

    [UIView animateWithDuration:2.f animations:^{

        alertLab.alpha = 0.f;

    }completion:^(BOOL finished) {

        [alertLab removeFromSuperview];

    }];

-(void)successTipsView:(NSString*)string{

    UILabel * alertLab = [[UILabelalloc] initWithFrame:CGRectMake(70,SCREEN_HEIGHT/2-20,SCREEN_WIDTH-70*2,20*2)];

    alertLab.backgroundColor = [UIColorwhiteColor];//设置背景色

    alertLab.textAlignment =NSTextAlignmentCenter;//剧中显示

    alertLab.text = string;//赋值

    alertLab.font = [UIFontsystemFontOfSize:16];//设置字体大小

    alertLab.textColor = [UIColorcolorWithHue:0.04saturation:0.88brightness:0.99alpha:1.00];//设置字体颜色

    [self.superviewaddSubview:alertLab];//添加到父视图上

    [UIViewanimateWithDuration:2.fanimations:^{

        alertLab.alpha =0.f;

    }completion:^(BOOL finished) {

        [alertLab removeFromSuperview];

    }];

}

0 0
原创粉丝点击