.h代码:
#import <UIKit/UIKit.h>
@interface XYCustomStatusbar : UIWindow
@property (nonatomic,strong)UIImageView *logoImageView;
@property (nonatomic,strong)UILabel *statusTextLabel;
+(instancetype)sharedStatusBar;
-(void)showStatusWithString:(NSString *)string;
-(void)hiddenStatusBar;
@end
.m代码:
#import "XYCustomStatusbar.h"
@interface XYCustomStatusbar()
@end
@implementation XYCustomStatusbar
static XYCustomStatusbar *_status;
+(instancetype)sharedStatusBar{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_status = [[XYCustomStatusbar alloc]init];
});
return _status;
}
-(instancetype)init{
if (self = [super init]) {
[self setupSubViews];
}
return self;
}
-(void)setupSubViews{
self.frame = [UIApplication sharedApplication].statusBarFrame;
self.windowLevel = UIWindowLevelStatusBar +1;
self.backgroundColor = [UIColor cyanColor];
self.hidden = true;
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(15, 0, 20, 20)];
[self addSubview:imageView];
imageView.backgroundColor = [UIColor colorWithRandomColor];
self.logoImageView = imageView;
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(40, 0, SCREEN_MAIN.width - 40, 20)];
[self addSubview:label];
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor colorWithRandomColor];
self.statusTextLabel = label;
}
-(void)showStatusWithString:(NSString *)string{
self.alpha = 0.0f;
self.hidden = false;
self.statusTextLabel.text = string;
[UIView animateWithDuration:0.1f animations:^{
self.alpha = 1.0f;
} completion:^(BOOL finished) {
}];
}
-(void)hiddenStatusBar{
[UIView animateWithDuration:0.1f animations:^{
self.alpha = 0.0f;
} completion:^(BOOL finished) {
self.hidden = true;
}];
}
@end
运用:
[[XYCustomStatusbar sharedStatusBar]showStatusWithString:str];//显示
[[XYCustomStatusbar sharedStatusBar]hiddenStatusBar];//消失
iOS 简单自定义状态栏(彷微博)
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 方法1:_staWindow是UIWindow类型,必须声明为全局变量 ··· CGRect rect = [UI...
- iOS有一个特有的功能--点击状态栏会使UIScollView自动滚动到顶部,这个效果其实是系统API里UIScr...
- 有时我们需要在页面中向上或向下滑动的时候执行一些事件,如果每次滑动都执行事件的话在有些情况下是不合理的,其实我们可...
- 4/100-20160430 本次文案学习来自数英网上的一篇:学习台湾民宿「缓慢adagio」的文案之道 喜欢这种...