Sportica   Sportica

iOS 渐变提示。错误弹出提示 几秒自动消失

//事例
 CGRect alertFarm = CGRectMake(20,20,100,50);
 [self noticeAlert:_bgView withNoticeStr:@"登录成功" withFram:alertFarm];

//渐变提示
+(void)noticeAlert:(UIView*)view withNoticeStr :(NSString*)str withFram :(CGRect)myFrame
{
    
    UIView *myView = [[UIView alloc]init];
    myView.frame = myFrame;
    [view addSubview:myView];
    
    UILabel *noticeLabel = [[UILabel alloc]init];
    noticeLabel.text = str;
    noticeLabel.font = [UIFont systemFontOfSize:13];
    noticeLabel.frame = myFrame;
    noticeLabel.textColor = [UIColor whiteColor];
    noticeLabel.textAlignment = NSTextAlignmentCenter;
    [myView addSubview:noticeLabel];
    //noticeLabel.layer.masksToBounds = YES;
    //noticeLabel.backgroundColor = [UIColor grayColor];
    
    noticeLabel.numberOfLines = 0;//表示label可以多行显示
    noticeLabel.lineBreakMode = NSLineBreakByClipping;
    CGSize size = [noticeLabel sizeThatFits:CGSizeMake(noticeLabel.frame.size.width, MAXFLOAT)];
    noticeLabel.frame =CGRectMake( 10, 10, noticeLabel.frame.size.width, size.height);  //size.height = 16
    
    //NSLog(@"heightheightheight:%f",size.height);
    myView.frame = CGRectMake(myFrame.origin.x, myFrame.origin.y - 7 - (size.height - 16), myFrame.size.width + 10, size.height +20);
    myView.backgroundColor = [UIColor blackColor];
    [myView.layer setCornerRadius:18];
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    [UIView setAnimationDuration:4.0];
    [UIView setAnimationDelegate:self];
    myView.alpha = 0.0;
    [UIView commitAnimations];
    
}

 

posted @ 2017-05-24 15:25  qingjoin  阅读(1138)  评论(0编辑  收藏  举报
  Sportica