简单的错误提示窗的实现

ErrorTipView.h


#import <UIKit/UIKit.h>

@interface ErrorTipView : UIView


-(id)initWithshowTipsOn:(UIView *)view andText:(NSString *)text andImagg:(UIImage *)image;



@end

ErrorTipView.m



#import "ErrorTipView.h"

@implementation ErrorTipView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/



-(id)initWithshowTipsOn:(UIView *)view andText:(NSString *)text andImagg:(UIImage *)image{

    if (self = [super init]) {
        //对该对象进行赋初始值
        
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = 5 * M_width;
        self.backgroundColor = RGBA(48, 48, 48, 1.0);
        [view addSubview:self];
        
        
        UIImageView * imageV = [[UIImageView alloc]initWithFrame:CGRectZero];
        imageV.image =image;
        [self addSubview:imageV];
        
        UILabel * tipsL = [[UILabel alloc]initWithFrame:CGRectZero];
        tipsL.font = [UIFont fontWithName:WENBENZITI size:14 * M_width];
        tipsL.textColor = [UIColor whiteColor];
        tipsL.numberOfLines = 0;
        tipsL.text = text;
        [tipsL sizeToFit];
        tipsL.textAlignment = NSTextAlignmentCenter;
        [self addSubview:tipsL];
        CGRect rect = [tipsL.text boundingRectWithSize:CGSizeMake(KWIDTH - 100 * M_width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName: tipsL.font} context:nil];

        if (image) {
            tipsL.frame = FRAME(33 * M_width, 52 * M_height,KWIDTH - 100 * M_width, rect.size.height);
            self.frame = FRAME(0, 0, tipsL.frame.size.width + 66 * M_width, rect.size.height + 72 * M_height);

        }else{
            tipsL.frame = FRAME(33 * M_width, 20 * M_height,KWIDTH - 100 * M_width, rect.size.height);

            self.frame = FRAME(0, 0, tipsL.frame.size.width + 66 * M_width, rect.size.height + 40 * M_height);

        }
        self.center = view.center;

        
        
        imageV.frame = FRAME(self.frame.size.width / 2 - 12 * M_width, 20 * M_height, 24 * M_width, 24 * M_width);
        
        [self performSelector:@selector(hide) withObject:nil afterDelay:2.0];
        
    }
    return self;
    
}


-(void)hide{
    [UIView animateWithDuration:0.8 animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值