脑袋显示提示,如tableview滑动提示滑回顶部
头部显示提示,如tableview滑动提示滑回顶部
@implementation TipsBar
UILabel *tipsLabel;
int width;
+ (void)showInView:(UIView *)view {
width = view.frame.size.width;
if (tipsLabel == nil) {
tipsLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, -20, view.frame.size.width, 20)];
tipsLabel.backgroundColor = [UIColor blackColor];
tipsLabel.textColor = [UIColor whiteColor];
tipsLabel.text = @"点击返回顶部";
tipsLabel.font = [UIFont systemFontOfSize:12];
tipsLabel.textAlignment = NSTextAlignmentCenter;
}
if ([[[UIApplication sharedApplication] delegate] window] != nil) {
[[[[UIApplication sharedApplication] delegate] window] addSubview:tipsLabel];
[[[[UIApplication sharedApplication] delegate] window] setWindowLevel:UIWindowLevelStatusBar];
}
[UIView animateWithDuration:0.3 animations:^{
tipsLabel.frame = CGRectMake(0, 0, view.frame.size.width, 20);
}];
}
+ (void)hide {
[UIView animateWithDuration:0.3 animations:^{
tipsLabel.frame = CGRectMake(0, -20, width, 20);
} completion:^(BOOL finished) {
[tipsLabel removeFromSuperview];
tipsLabel = nil;
}];
}
头部显示提示,如tableview滑动提示滑回顶部
by 伍雪颖
就是在[[[UIApplication
sharedApplication]
delegate]
window]添加要的内容:
#import "TipsBar.h"
@implementation TipsBar
UILabel *tipsLabel;
int width;
+ (void)showInView:(UIView *)view {
width = view.frame.size.width;
if (tipsLabel == nil) {
tipsLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, -20, view.frame.size.width, 20)];
tipsLabel.backgroundColor = [UIColor blackColor];
tipsLabel.textColor = [UIColor whiteColor];
tipsLabel.text = @"点击返回顶部";
tipsLabel.font = [UIFont systemFontOfSize:12];
tipsLabel.textAlignment = NSTextAlignmentCenter;
}
if ([[[UIApplication sharedApplication] delegate] window] != nil) {
[[[[UIApplication sharedApplication] delegate] window] addSubview:tipsLabel];
[[[[UIApplication sharedApplication] delegate] window] setWindowLevel:UIWindowLevelStatusBar];
}
[UIView animateWithDuration:0.3 animations:^{
tipsLabel.frame = CGRectMake(0, 0, view.frame.size.width, 20);
}];
}
+ (void)hide {
[UIView animateWithDuration:0.3 animations:^{
tipsLabel.frame = CGRectMake(0, -20, width, 20);
} completion:^(BOOL finished) {
[tipsLabel removeFromSuperview];
tipsLabel = nil;
}];
}
@end