您的位置:首页 > 移动开发 > IOS开发

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

2017-05-24 15:25 513 查看
//事例
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];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: