分享

在iOS中实现类似安卓自动消失提示框

 昵称21039582 2015-03-06


#import <Foundation/Foundation.h>

@interface ShowMessage : NSObject

+(void)showMessage:(NSString *)message;

@end



#import "ShowMessage.h"


@implementation ShowMessage

+(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((WIDTH - LabelSize.width - 20)/2, HEIGHT/2, LabelSize.width+20, LabelSize.height+10);

    [UIView animateWithDuration:2 animations:^{

        showview.alpha = 0;

    } completion:^(BOOL finished) {

        [showview removeFromSuperview];

    }];

}

@end

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多