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;

你可能感兴趣的:(提示框,吐司,AlertView,ios提示框,totast)