首页 > 代码库 > 状态栏的提示

状态栏的提示

状态栏的提示

by 伍雪颖


@property (nonatomic, strong) UIWindow *window;
@property (nonatomic, strong) UILabel *meterLabel;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.window = [[UIWindow alloc] initWithFrame:[UIApplication sharedApplication].statusBarFrame];
    self.window.windowLevel = UIWindowLevelStatusBar + 10.0;
    self.window.userInteractionEnabled = NO;
    
    CGFloat const kMeterWidth = 165.0;
    self.meterLabel = [[UILabel alloc] initWithFrame:CGRectMake((CGRectGetWidth(self.window.bounds) - kMeterWidth) / 2.0, 0.0,
                                                                kMeterWidth, CGRectGetHeight(self.window.bounds))];
    self.meterLabel.font = [UIFont boldSystemFontOfSize:12.0];
    self.meterLabel.backgroundColor = [UIColor blackColor];
    self.meterLabel.textColor = [UIColor whiteColor];
    self.meterLabel.textAlignment = NSTextAlignmentCenter;
    self.meterLabel.text = @"touch here to go back";
    [self.window addSubview:self.meterLabel];
    self.window.hidden = NO;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.window = nil;
    });
}


状态栏的提示