首页 > 代码库 > 头部显示提示,如tableview滑动提示滑回顶部

头部显示提示,如tableview滑动提示滑回顶部

头部显示提示,如tableview滑动提示滑回顶部

by 伍雪颖

技术分享

就是在[[[UIApplicationsharedApplication]delegate]window]添加要的内容:

#import "TipsBar.h"

@implementation TipsBar

UILabel *tipsLabel;
int width;
+ (
void)showInView:(UIView *)view {
   
width = view.frame.size.width;
   
if (tipsLabel ==nil) {
       
tipsLabel = [[UILabelalloc]initWithFrame:CGRectMake(0, -20, view.frame.size.width,20)];
       
tipsLabel.backgroundColor = [UIColorblackColor];
       
tipsLabel.textColor = [UIColorwhiteColor];
       
tipsLabel.text =@"点击返回顶部";
       
tipsLabel.font = [UIFontsystemFontOfSize:12];
       
tipsLabel.textAlignment =NSTextAlignmentCenter;
    }
   
if ([[[UIApplicationsharedApplication]delegate]window] !=nil) {
        [[[[
UIApplicationsharedApplication]delegate]window]addSubview:tipsLabel];
        [[[[
UIApplicationsharedApplication]delegate]window]setWindowLevel:UIWindowLevelStatusBar];
    }
    [
UIViewanimateWithDuration:0.3animations:^{
       
tipsLabel.frame =CGRectMake(0,0, view.frame.size.width,20);
    }];
}

+ (
void)hide {
    [
UIViewanimateWithDuration:0.3animations:^{
       
tipsLabel.frame =CGRectMake(0, -20,width,20);
    }
completion:^(BOOL finished) {
        [
tipsLabelremoveFromSuperview];
       
tipsLabel =nil;
    }];
}

@end

头部显示提示,如tableview滑动提示滑回顶部