zoukankan      html  css  js  c++  java
  • 在iOS中实现类似安卓自动消失提示框

    类方法:

    + (void)showMessage:(NSString *)message {
        // 获取window
        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];
        UIFont *font = [UIFont systemFontOfSize:15];
        CGRect labelRect = [message boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 30) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: font} context:nil];
        label.frame = CGRectMake(10, 5, ceil(CGRectGetWidth(labelRect)), CGRectGetHeight(labelRect));
        label.text = message;
        label.textColor = [UIColor whiteColor];
        label.font = [UIFont systemFontOfSize:15];
        label.textAlignment = NSTextAlignmentCenter;
        label.backgroundColor = [UIColor clearColor];
        [showView addSubview:label];
        showView.frame = CGRectMake((SCREEN_WIDTH - CGRectGetWidth(labelRect) - 20)/2, 100, CGRectGetWidth(labelRect)+20, CGRectGetHeight(labelRect)+10);
        [UIView animateWithDuration:1.5 animations:^{
            showView.alpha = 0;
        } completion:^(BOOL finished) {
            [showView removeFromSuperview];
        }];
        
    }
  • 相关阅读:
    redux-simple 简化版的redux
    react服务端渲染(同构)
    使用systemd管理程序进程
    使用Dockerfile构建镜像
    centos7使用supermin制作centos7的docker镜像包
    DNS-dnsmasq安装配置
    kubernetes-部署(单机,使用证书)
    DNS-bind+namedmanager安装
    python3第一个脚本(hello world!)
    Python3 基础语法
  • 原文地址:https://www.cnblogs.com/mafeng/p/5880415.html
Copyright © 2011-2022 走看看