ios 类似android的toast
2015-09-12 17:24
411 查看
经常碰到一些项目功能未全部开发完整需要上线的app,那么第一要做的事情,就是在提交appstore的app界面的审核信息的备注一栏需要文字说明,中文即可。然后就是工程里给用户比较好的提示功能未开发,android有吐司,比较适合。ios的alertview自定义比较麻烦,下面的方法就可以比较好的满足你的需求,类似android的totast。
-(void)showMessage:(NSString *)message
{
UIWindow * window = [UIApplication sharedApplication].keyWindow;
UIView *showview = [[UIView alloc]init];
showview.backgroundColor = [UIColor blackColor];
showview.frame = CGRectMake(1, 1, 1, 1);
showview.alpha = 1.0f;
showview.layer.cornerRadius = 5.0f;
showview.layer.masksToBounds = YES;
[window addSubview:showview];
}
调用示例
[self showMessage:@”正在开发,敬请期待。”]
说明:
CGSize LabelSize = [message sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(290, 9000)]; 这个方法已经被弃用了,但是还是可以使用,如果你有变异洁癖的话,可以替换成如下代码
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:12], NSParagraphStyleAttributeName:paragraphStyle.copy};
CGSize labelSize = [self.shopModel.address boundingRectWithSize:CGSizeMake(KScreenWidth-20, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes1 context:nil].size;
-(void)showMessage:(NSString *)message
{
UIWindow * window = [UIApplication sharedApplication].keyWindow;
UIView *showview = [[UIView alloc]init];
showview.backgroundColor = [UIColor blackColor];
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]; CGSize LabelSize = [message sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(290, 9000)]; label.frame = CGRectMake(10, 5, LabelSize.width, 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((SCREEN_WIDTH - LabelSize.width - 20)/2, SCREEN_HEIGHT - 100, LabelSize.width+20, LabelSize.height+10); [UIView animateWithDuration:1.5 animations:^{ showview.alpha = 0; } completion:^(BOOL finished) { [showview removeFromSuperview]; }];
}
调用示例
[self showMessage:@”正在开发,敬请期待。”]
说明:
CGSize LabelSize = [message sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(290, 9000)]; 这个方法已经被弃用了,但是还是可以使用,如果你有变异洁癖的话,可以替换成如下代码
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:12], NSParagraphStyleAttributeName:paragraphStyle.copy};
CGSize labelSize = [self.shopModel.address boundingRectWithSize:CGSizeMake(KScreenWidth-20, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes1 context:nil].size;
相关文章推荐
- Android 数据存数---SQLite数据库
- Android实战简易教程-第五十七枪(分享小米手电筒源码)
- 2016最新Android安卓短信拦截(过Android4.4和Android5.0和Android5.1)源码
- Android中Popupwindow和Dialog的区别
- Android中Popupwindow和Dialog的区别
- Android中Popupwindow和Dialog的区别
- Android Studio SVN 出现“Subversion command line client version is too old”
- android中修改actionbar的背景颜色和字体颜色等
- Intent深入解剖
- Android下ListView的学习
- Git 常用命令
- 导入Android自带Sample工程出错解决(Error retrieving parent for item)
- Android中的颜色设置
- Android中的颜色设置
- Android 之 自定义标签 和 自定义组件 TypedArray
- Android(java)学习笔记234: 服务(service)之音乐播放器
- Android下相机的调用
- Android Studio打包签名全过程
- Android Studio打包签名全过程
- Windows环境下Android Studio v1.0安装教程