如何在APP内部进行实现APP的顶部弹框

版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/dkq972958298/article/details/52737297

在iOS开发中,可能有的地方会需要用到在使用APP的时候,如果有有消息,需要提醒一下,可以使用顶部的消息提醒一下,我写了一下提醒框,然后效果是这样的:

实现的方法:

@interface RKDropdownAlert : UIButton

//如果为空调用该方法
+(void)show;

//设置标题
+(void)title:(NSString*)title;

//设置只有标题的情况下现实的时间
+(void)title:(NSString*)title time:(NSInteger)seconds;

/*
 title  标题
 backgroundColor 背景颜色
 textColor 字体颜色
 */
+(void)title:(NSString*)title backgroundColor:(UIColor*)backgroundColor textColor:(UIColor*)textColor;

/*
 title  标题
 backgroundColor 背景颜色
 textColor 字体颜色
 time      时间
 */
+(void)title:(NSString*)title backgroundColor:(UIColor*)backgroundColor textColor:(UIColor*)textColor time:(NSInteger)seconds;

/*
 title  标题
 message 消息内容
 backgroundColor 背景颜色
 textColor 字体颜色
 time      时间
 */
+(void)title:(NSString*)title message:(NSString*)message backgroundColor:(UIColor*)backgroundColor textColor:(UIColor*)textColor time:(NSInteger)seconds;

具体方法的实现

-(void)title:(NSString*)title message:(NSString*)message backgroundColor:(UIColor*)backgroundColor textColor:(UIColor*)textColor time:(NSInteger)seconds
{
    NSInteger time = seconds;
    titleLabel.text = title;
    
    if (message && message.length > 0) {
        messageLabel.text = message;
        if ([self messageTextIsOneLine]) {
            CGRect frame = titleLabel.frame;
            frame.origin.y = STATUS_BAR_HEIGHT+5;
            titleLabel.frame = frame;
        }
    } else {
        CGRect frame = titleLabel.frame;
        frame.size.height = HEIGHT-2*Y_BUFFER-STATUS_BAR_HEIGHT;
        frame.origin.y = Y_BUFFER+STATUS_BAR_HEIGHT;
        titleLabel.frame = frame;
    }
    
    if (backgroundColor) {
        self.backgroundColor = backgroundColor;
    }
    if (textColor) {
        titleLabel.textColor = textColor;
        messageLabel.textColor = textColor;
    }
    
    if (seconds == -1) {
        time = TIME;
    }
    
    if(!self.superview){
        NSEnumerator *frontToBackWindows = [[[UIApplication sharedApplication]windows]reverseObjectEnumerator];
        
        for (UIWindow *window in frontToBackWindows)
            if (window.windowLevel == UIWindowLevelNormal && !window.hidden) {
                [window addSubview:self];
                break;
            }
    }
    
    self.isShowing = YES;
    
    [UIView animateWithDuration:ANIMATION_TIME animations:^{
        CGRect frame = self.frame;
        frame.origin.y = 0;
        self.frame = frame;
    }];
    
    [self performSelector:@selector(viewWasTapped:) withObject:self afterDelay:time+ANIMATION_TIME];
}


代码下载地址:https://github.com/fenglingdeyi/ShowAlert





展开阅读全文

没有更多推荐了,返回首页