ios 类似android的toast
经常碰到一些项目功能未全部开发完整需要上线的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];
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时出现path问题,因为路径有中文,完美解决方法
- Android快速实现地图功能(不仅快!而且小!)
- 详解Android进程保活的方法
- Phone Gap开发二:开发一个Phone Gap插件
- BroadcastReceiver、EventBus的优缺点
- Android(安卓)Bottom Sheet详解
- Android实现简单的音乐播放
- Android--Handler的使用方法:在子线程中更新界面
- 官宣:微软Cortana或将退出Android/iOS两大平台