iOS一个简单的提示条代码

释放双眼,带上耳机,听听看~!

提示条用法

  • 将下面代码放到任意想出现提示消息的地方
 [self showMessage:[NSString stringWithFormat:@"我是提示"] duration:3];
  • 也可以这样,作为可变的提示条
[self showMessage:[NSString stringWithFormat:@"密码为 : %@",Password] duration:3];

使用前提是在代码段后面加上如下一段代码即可:

PS:可无脑粘贴 位置可自定义变化

#pragma mark  提示条
-(void)showMessage:(NSString *)message duration:(NSTimeInterval)time
{
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
UIWindow * window = [UIApplication sharedApplication].keyWindow;
UIView *showview =  [[UIView alloc]init];
showview.backgroundColor = [UIColor grayColor];
showview.frame = CGRectMake(1, 1, 1, 1);
showview.alpha = 1.0f;
showview.layer.cornerRadius = 5.0f;
showview.layer.masksToBounds = YES;
[window addSubview:showview];
UILabel *label = [[UILabel alloc]init];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15.f],
NSParagraphStyleAttributeName:paragraphStyle.copy};
CGSize labelSize = [message boundingRectWithSize:CGSizeMake(207, 999)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:attributes context:nil].size;
label.frame = CGRectMake(10, 5, labelSize.width +20, labelSize.height);
label.text = message;
label.textColor = [UIColor whiteColor];
label.textAlignment = 1;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:15];
[showview addSubview:label];
showview.frame = CGRectMake((screenSize.width - labelSize.width - 20)/2,
screenSize.height - 300,
labelSize.width+40,
labelSize.height+10);
[UIView animateWithDuration:time animations:^{
showview.alpha = 0;
} completion:^(BOOL finished) {
[showview removeFromSuperview];
}];
}

 

人已赞赏
iOS文章

ios开发日常之XCode 文件后面带有问号的问题解决

2020-5-15 11:03:01

iOS文章

iOS开发-定制多样式二维码

2020-5-15 12:18:03

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索