1010cc时时彩标准版 > 操作系统 > 自定义状态栏代码详解,ios类似于安卓toast的唤醒

原标题:自定义状态栏代码详解,ios类似于安卓toast的唤醒

浏览次数:147 时间:2019-08-18

iOS疯狂详解之自定义状态栏代码解析

   这里说明一下,Apple没有开放的状态栏的API,在ios 的官方文档没有提到修改Window Level的方式;

  先看一下Window Level的可用的值包括:

  1: typedef CGFloat UIWindowLevel;

  2: const UIWindowLevel UIWindowLevelNormal; // 0.0

  3: const UIWindowLevel UIWindowLevelAlert; // 2000.0

  4: const UIWindowLevel UIWindowLevelStatusBar; // 1000.0

  默认我们的UIView layer都是在UIWindowLevelNormal上,这也就是为什么系统弹出来的对话框在我们的视图之上,因为它的Window Level级别更高。

  根据WindowLevel的原理我们也就知道,如果想在系统的状态栏上,添加自定义的状态栏,就需要比UIWindowLevelStatusBar的级别更高,接下来,用代码说明一下:

  首先,先建一个Single View Application,名字自定义就可以了,

  然后,新建一个类命名为: StatusBarOverlay 继承自UIWindow类,代码:

  StatusBarOverlay.h文件

  1: #import

  2:

  3: @interface StatusBarOverlay : UIWindow{

  4: UIView *contentView;

  5: UILabel *textLabel;

  6: }

  7:

  8: @property (nonatomic, retain) UIView *contentView;

  9:

  10: @property (nonatomic, retain) UILabel *textLabel;

  11:

  12: @end

  StatusBarOverlay.m文件

  1: //

  2: // StatusBarOverlay.m

  3: // StatusBarDemo

  4: //

  5: // Created by jordy wang on 12-8-7.

  6: // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.

  7: //

  8:

  9: #import "StatusBarOverlay.h"

  10:

  11: #define STATUS_BAR_ORIENTATION [UIApplication sharedApplication].statusBarOrientation

  12: #define ROTATION_ANIMATION_DURATION [UIApplication sharedApplication].statusBarOrientationAnimationDuration

  13:

  14:

  15: @interface StatusBarOverlay()

  16:

  17: - (void)initializeToDefaultState;

  18: - (void)rotateStatusBarWithFrame:(NSValue *)frameValue;

  19: - (void)setSubViewHFrame;

  20: - (void)setSubViewVFrame;

  21: @end

  22:

  23:

  24: @implementation StatusBarOverlay

  25: @synthesize contentView;

  26: @synthesize textLabel;

  27:

  28: //重写init方法

  29: - (id)init

  30: {

  31: self = [super initWithFrame:CGRectZero];

  32: if (self) {

  33: self.windowLevel = UIWindowLevelStatusBar 1;

  34: self.frame = [UIApplication sharedApplication].statusBarFrame;

  35: [self setBackgroundColor:[UIColor orangeColor]];

  36: [self setHidden:NO];

  37:

  38: //内容视图

  39: UIView *_contentView = [[UIView alloc] initWithFrame:self.bounds];

  40: self.contentView = _contentView;

  41: [self.contentView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];

  42: [self.contentView setBackgroundColor:[UIColor cyanColor]];

  43: [self addSubview:self.contentView];

  44: [_contentView release];

  45:

  46:

  47: //添加textLabel

  48: UILabel *_textLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 0, CGRectGetWidth(self.frame)-60, CGRectGetHeight(self.frame))];

  49: self.textLabel = _textLabel;

  50: [self.textLabel setBackgroundColor:[UIColor blueColor]];

  51: [self.textLabel setFont:[UIFont systemFontOfSize:12]];

  52: [self.textLabel setTextAlignment:UITextAlignmentCenter];

  53: [self.textLabel setTextColor:[UIColor blackColor]];

  54: [self.textLabel setText:@"自定义的状态栏 author by jordy"];

  55: [self.contentView addSubview:self.textLabel];

  56: [_textLabel release];

  57:

  58: //注册监听---当屏幕将要转动时,所出发的事件(用于操作本视图改变其frame)

  59: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willRotateScreenEvent:) name:UIApplicationWillChangeStatusBarFrameNotification object:nil];

  60: //初始化

  61: [self initializeToDefaultState];

  62: }

  63:

  64: return self;

  65: }

  66:

  67:

  68:

  69:

  70: //初始化为默认状态

  71: - (void)initializeToDefaultState

  72: {

  73: //获取当前的状态栏位置

  74: CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;

  75: //设置当前视图的旋转, 根据当前设备的朝向

  76: [self rotateStatusBarWithFrame:[NSValue valueWithCGRect:statusBarFrame]];

  77:

  78:

  79:

  80: }

  81:

  82:

  83: //旋转屏幕

  84: - (void)rotateStatusBarWithFrame:(NSValue *)frameValue

  85: {

  86: CGRect frame = [frameValue CGRectValue];

  87: UIInterfaceOrientation orientation = STATUS_BAR_ORIENTATION;

  88:

  89: if (orientation == UIDeviceOrientationPortrait) {

  90: self.transform = CGAffineTransformIdentity; //屏幕不旋转

  91: [self setSubViewVFrame];

  92: }else if (orientation == UIDeviceOrientationPortraitUpsideDown) {

  93: self.transform = CGAffineTransformMakeRotation(M_PI); //屏幕旋转180度

  94: [self setSubViewVFrame];

  95: }else if (orientation == UIDeviceOrientationLandscapeRight) {

  96: self.transform = CGAffineTransformMakeRotation((M_PI * (-90.0f) / 180.0f)); //屏幕旋转-90度

  97: [self setSubViewHFrame];

  98: }else if (orientation == UIDeviceOrientationLandscapeLeft){

  99: self.transform = CGAffineTransformMakeRotation(M_PI * 90.0f / 180.0f); //屏幕旋转90度

  100: [self setSubViewHFrame];

  101: }

  102:

  103: self.frame = frame;

  104: [self.contentView setFrame:self.bounds];

  105: }

  106:

  107: //设置横屏的子视图的frame

  108: - (void)setSubViewHFrame

  109: {

  110: self.textLabel.frame = CGRectMake(30, 0, 1024-60, 20);

  111: }

  112: //设置竖屏的子视图的frame

  113: - (void)setSubViewVFrame

  114: {

  115: self.textLabel.frame = CGRectMake(30, 0, 748-60, 20);

  116: }

  117:

  118: #pragma mark -

  119: #pragma mark 响应屏幕即将旋转时的事件响应

  120: - (void)willRotateScreenEvent:(NSNotification *)notification

  121: {

  122: NSValue *frameValue = [notification.userInfo valueForKey:UIApplicationStatusBarFrameUserInfoKey];

  123: [self rotateStatusBarAnimatedWithFrame:frameValue];

  124: }

  125:

  126: - (void)rotateStatusBarAnimatedWithFrame:(NSValue *)frameValue {

  127: [UIView animateWithDuration:ROTATION_ANIMATION_DURATION animations:^{

  128: self.alpha = 0;

  129: } completion:^(BOOL finished) {

  130: [self rotateStatusBarWithFrame:frameValue];

  131: [UIView animateWithDuration:ROTATION_ANIMATION_DURATION animations:^{

  132: self.alpha = 1;

  133: }];

  134: }];

  135: }

  136:

  137: - (void)dealloc

  138: {

  139: [[NSNotificationCenter defaultCenter] removeObserver:self];

  140: [textLabel release];

  141: textLabel = nil;

  142:

  143: [contentView release];

  144: contentView = nil;

  145:

  146: [super dealloc];

  147: }

  148:

  149: @end

  由于代码比较简单,并且我在上述代码里有相应的注释,这里需要说明一点的是,默认我们继承自UIWindow的StatusBarOverlay类是hidden状态,需要在初始化的时候设置它的hidden属性为NO,

  在屏幕旋转过程中,自定义的状态栏与UIViewController之间的旋转是分离的,所以我们需要做一个隐藏的动画,在旋转过程前先隐藏自定义的状态栏,旋转结果后设置显示状态。

  如果需要做一种动画,比方从底部下移显示一条信息,隔N秒后又自动收回的动画,直接设置自定义的视图的y坐标就可以了,默认y坐标设置是0。

  最后, 使用它的方式也比较简单,只需要初始化,代码:

  StatusBarOverlay *statusBarOverlay = [[StatusBarOverlay alloc] init];

  由于我公司的需求是开机自动下载的功能,所以我在初始化的时候,是放在了AppDelegate中。

这里说明一下,Apple没有开放的状态栏的API,在ios 的官方文档没有提到修改Window Level的方式; 先看一下...

iOS开发:自定义状态栏代码详解

   公司的开发的项目要求在状态栏上边加入程序下载的进度条,之前写的程序,由于是根据ipad的朝向来设置自定义的状态栏的frame,以及子视图的 frame和transform,出现一些不太容易解决的bug。这两天正好项目不太紧,就好好学习一下这方面的知识,以下是我所总结的一点经验:

  这里说明一下,Apple没有开放的状态栏的API,在ios 的官方文档没有提到修改Window Level的方式;

  先看一下Window Level的可用的值包括:

  1: typedef CGFloat UIWindowLevel;

  2: const UIWindowLevel UIWindowLevelNormal; // 0.0

  3: const UIWindowLevel UIWindowLevelAlert; // 2000.0

  4: const UIWindowLevel UIWindowLevelStatusBar; // 1000.0

  默认我们的UIView layer都是在UIWindowLevelNormal上,这也就是为什么系统弹出来的对话框在我们的视图之上,因为它的Window Level级别更高。

  根据WindowLevel的原理我们也就知道,如果想在系统的状态栏上,添加自定义的状态栏,就需要比UIWindowLevelStatusBar的级别更高,接下来,用代码说明一下:

  首先,先建一个Single View Application,名字自定义就可以了,

  然后,新建一个类命名为: StatusBarOverlay 继承自UIWindow类,代码:

  StatusBarOverlay.h文件

  1: #import

  2:

  3: @interface StatusBarOverlay : UIWindow{

  4: UIView *contentView;

  5: UILabel *textLabel;

  6: }

  7:

  8: @property (nonatomic, retain) UIView *contentView;

  9:

  10: @property (nonatomic, retain) UILabel *textLabel;

  11:

  12: @end

  StatusBarOverlay.m文件

  1: //

  2: // StatusBarOverlay.m

  3: // StatusBarDemo

  4: //

  5: // Created by jordy wang on 12-8-7.

  6: // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.

  7: //

  8:

  9: #import "StatusBarOverlay.h"

  10:

  11: #define STATUS_BAR_ORIENTATION [UIApplication sharedApplication].statusBarOrientation

  12: #define ROTATION_ANIMATION_DURATION [UIApplication sharedApplication].statusBarOrientationAnimationDuration

  13:

  14:

  15: @interface StatusBarOverlay()

  16:

  17: - (void)initializeToDefaultState;

  18: - (void)rotateStatusBarWithFrame:(NSValue *)frameValue;

  19: - (void)setSubViewHFrame;

  20: - (void)setSubViewVFrame;

  21: @end

  22:

  23:

  24: @implementation StatusBarOverlay

  25: @synthesize contentView;

  26: @synthesize textLabel;

  27:

  28: //重写init方法

  29: - (id)init

  30: {

  31: self = [super initWithFrame:CGRectZero];

  32: if (self) {

  33: self.windowLevel = UIWindowLevelStatusBar 1;

  34: self.frame = [UIApplication sharedApplication].statusBarFrame;

  35: [self setBackgroundColor:[UIColor orangeColor]];

  36: [self setHidden:NO];

  37:

  38: //内容视图

  39: UIView *_contentView = [[UIView alloc] initWithFrame:self.bounds];

  40: self.contentView = _contentView;

  41: [self.contentView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];

  42: [self.contentView setBackgroundColor:[UIColor cyanColor]];

  43: [self addSubview:self.contentView];

  44: [_contentView release];

  45:

  46:

  47: //添加textLabel

  48: UILabel *_textLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 0, CGRectGetWidth(self.frame)-60, CGRectGetHeight(self.frame))];

  49: self.textLabel = _textLabel;

  50: [self.textLabel setBackgroundColor:[UIColor blueColor]];

  51: [self.textLabel setFont:[UIFont systemFontOfSize:12]];

  52: [self.textLabel setTextAlignment:UITextAlignmentCenter];

  53: [self.textLabel setTextColor:[UIColor blackColor]];

  54: [self.textLabel setText:@"自定义的状态栏 author by jordy"];

  55: [self.contentView addSubview:self.textLabel];

  56: [_textLabel release];

  57:

  58: //注册监听---当屏幕将要转动时,所出发的事件(用于操作本视图改变其frame)

  59: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willRotateScreenEvent:)

  name:UIApplicationWillChangeStatusBarFrameNotification object:nil];

  60: //初始化

  61: [self initializeToDefaultState];

  62: }

  63:

  64: return self;

  65: }

  66:

  67:

  68:

  69:

  70: //初始化为默认状态

  71: - (void)initializeToDefaultState

  72: {

  73: //获取当前的状态栏位置

  74: CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;

  75: //设置当前视图的旋转, 根据当前设备的朝向

  76: [self rotateStatusBarWithFrame:[NSValue valueWithCGRect:statusBarFrame]];

  77:

  78:

  79:

  80: }

  81:

  82:

  83: //旋转屏幕

  84: - (void)rotateStatusBarWithFrame:(NSValue *)frameValue

  85: {

  86: CGRect frame = [frameValue CGRectValue];

  87: UIInterfaceOrientation orientation = STATUS_BAR_ORIENTATION;

  88:

  89: if (orientation == UIDeviceOrientationPortrait) {

  90: self.transform = CGAffineTransformIdentity; //屏幕不旋转

  91: [self setSubViewVFrame];

  92: }else if (orientation == UIDeviceOrientationPortraitUpsideDown) {

  93: self.transform = CGAffineTransformMakeRotation(M_PI); //屏幕旋转180度

  94: [self setSubViewVFrame];

  95: }else if (orientation == UIDeviceOrientationLandscapeRight) {

  96: self.transform = CGAffineTransformMakeRotation((M_PI * (-90.0f) / 180.0f)); //屏幕旋转-90度

  97: [self setSubViewHFrame];

  98: }else if (orientation == UIDeviceOrientationLandscapeLeft){

  99: self.transform = CGAffineTransformMakeRotation(M_PI * 90.0f / 180.0f); //屏幕旋转90度

  100: [self setSubViewHFrame];

  101: }

  102:

  103: self.frame = frame;

  104: [self.contentView setFrame:self.bounds];

  105: }

  106:

  107: //设置横屏的子视图的frame

  108: - (void)setSubViewHFrame

  109: {

  110: self.textLabel.frame = CGRectMake(30, 0, 1024-60, 20);

  111: }

  112: //设置竖屏的子视图的frame

  113: - (void)setSubViewVFrame

  114: {

  115: self.textLabel.frame = CGRectMake(30, 0, 748-60, 20);

  116: }

  117:

  118: #pragma mark -

  119: #pragma mark 响应屏幕即将旋转时的事件响应

  120: - (void)willRotateScreenEvent:(NSNotification *)notification

  121: {

  122: NSValue *frameValue = [notification.userInfo valueForKey:UIApplicationStatusBarFrameUserInfoKey];

  123: [self rotateStatusBarAnimatedWithFrame:frameValue];

  124: }

  125:

  126: - (void)rotateStatusBarAnimatedWithFrame:(NSValue *)frameValue {

  127: [UIView animateWithDuration:ROTATION_ANIMATION_DURATION animations:^{

  128: self.alpha = 0;

  129: } completion:^(BOOL finished) {

  130: [self rotateStatusBarWithFrame:frameValue];

  131: [UIView animateWithDuration:ROTATION_ANIMATION_DURATION animations:^{

  132: self.alpha = 1;

  133: }];

  134: }];

  135: }

  136:

  137: - (void)dealloc

  138: {

  139: [[NSNotificationCenter defaultCenter] removeObserver:self];

  140: [textLabel release];

  141: textLabel = nil;

  142:

  143: [contentView release];

  144: contentView = nil;

  145:

  146: [super dealloc];

  147: }

  148:

  149: @end

  由于代码比较简单,并且我在上述代码里有相应的注释,这里需要说明一点的是,默认我们继承自UIWindow的StatusBarOverlay类是hidden状态,需要在初始化的时候设置它的hidden属性为NO,

  在屏幕旋转过程中,自定义的状态栏与UIViewController之间的旋转是分离的,所以我们需要做一个隐藏的动画,在旋转过程前先隐藏自定义的状态栏,旋转结果后设置显示状态。

  如果需要做一种动画,比方从底部下移显示一条信息,隔N秒后又自动收回的动画,直接设置自定义的视图的y坐标就可以了,默认y坐标设置是0。

  最后, 使用它的方式也比较简单,只需要初始化,代码:

  StatusBarOverlay *statusBarOverlay = [[StatusBarOverlay alloc] init];

  由于我公司的需求是开机自动下载的功能,所以我在初始化的时候,是放在了AppDelegate中。

公司的开发的项目要求在状态栏上边加入程序下载的进度条,之前写的程序,由于是根据ipad的朝向来设置...

ios自定义状态栏显示发送结果

自定义状态栏,首先需要隐藏系统的statusbar然后重新显示一个window即可

直接上代码,可以直接使用:

//

// CustomStatusBar.h

// CustomStatusBar

//

// Created by yb on 14/10/24.

// Copyright (c) 2014年 yb. All rights reserved.

//

#import

@interface CustomStatusBar : UIWindow

- (void)showStatusMessage:(NSString *)message;

- (void)hideStatusBarWhenSendFinished;

-(void)hideStatusBarWhenSendFailed;

@end

//

// CustomStatusBar.m

// CustomStatusBar

//

// Created by yb on 14/10/24.

// Copyright (c) 2014年 yb. All rights reserved.

//

#import "CustomStatusBar.h"

@interface CustomStatusBar ()

@property(strong,nonatomic)UILabel *messageLabel;

@end

@implementation CustomStatusBar

- (instancetype)init

{

self = [super init];

if (self) {

self.frame=[UIApplication sharedApplication].statusBarFrame;

self.backgroundColor=[UIColor blackColor];

self.windowLevel=UIWindowLevelStatusBar 1.0f;

self.messageLabel=[[UILabel alloc]initWithFrame:self.bounds];

self.messageLabel.textColor=[UIColor whiteColor];

self.messageLabel.textAlignment=NSTextAlignmentCenter;

[self addSubview:_messageLabel];

}

return self;

}

- (void)showStatusMessage:(NSString *)message

{

self.hidden = NO;

self.alpha = 1.0f;

self.frame=[UIApplication sharedApplication].statusBarFrame;

self.messageLabel.frame=self.bounds;

CGSize totalSize = self.frame.size;

self.frame = (CGRect){ self.frame.origin, 0, totalSize.height };

[UIView animateWithDuration:0.5f animations:^{

self.frame = (CGRect){ self.frame.origin, totalSize };

self.messageLabel.text = message;

} completion:^(BOOL finished)

{

}];

}

- (void)hideStatusBarWhenSendFinished

{

self.alpha = 1.0f;

[UIView animateWithDuration:2.0f animations:^

{

self.alpha = 0.0f;

CGRect frame=self.frame;

frame.size.height=0;

self.frame=frame;

[email protected]"发送成功!";

} completion:^(BOOL finished){

self.frame=CGRectZero;

self.hidden = YES;

}];;

}

-(void)hideStatusBarWhenSendFailed

{

self.alpha = 1.0f;

[UIView animateWithDuration:2.0f animations:^

{

self.alpha = 0.0f;

CGRect frame=self.frame;

frame.size.height=0;

self.frame=frame;

[email protected]"发送失败!";

} completion:^(BOOL finished){

self.frame=CGRectZero;

self.hidden = YES;

}];;

}

@end

自定义状态栏,首先需要隐藏系统的statusbar然后重新显示一个window即可 直接上代码,可以直接使用: // // Custom...

#import "JRToast.h"

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES; //显示
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO; //隐藏
让状态栏显示网络等待标志
状态栏是可以通过UIApplication类提供的一些方法来修改的,比如完全去掉状态栏或者修改风格,不过这些改变只是在你的程序内部,当你退出你的程序又会复原。

@interface JRToast ()

UIApplication *myApp = [UIapplication sharedApplication];
复制代码
1.隐藏状态栏

- (instancetype)initWithText:(NSString *)text;

[myApp setStatusBarHidden:YES animated:YES];
复制代码
记得隐藏状态栏后的你的“桌面”就增加320×20的大小,所以最好是在任何window或者view创建之前隐藏它。
2.状态栏风格
[myApp setStatusBarStyle: UIStatusbarStyleBlackOpaque];
复制代码
typedef enum {
UIStatusBarStyleDefault,
UIStatusBarStyleBlackTranslucent,
UIStatusBarStyleBlackOpaque
} UIStatusBarStyle;
复制代码
3.状态栏方向
[myApp setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
复制代码
typedef enum {
UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,
//竖屏,垂直向上
UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
//竖屏,垂直方向上下颠倒
UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight,
//设备逆时针旋转到横屏模式
UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft
//设备顺时针旋转到横屏模式
} UIInterfaceOrientation;
复制代码

- (void)setDuration:(CGFloat)duration;

有时候,需要在状态栏上显示一些自定义信息,比如新浪微博的官方iOS客户端:告知用户信息处于发送队列、发送成功或者发送失败。

- (void)dismissToast;

如上图,通过在状态栏显示自定义信息,可以给用户友好又不影响软件使用的提示。

- (void)toastTaped:(UIButton *)button;

为此,我们显得定义一个自定义状态栏类,包含一个显示信息的Label:

- (void)showAnimation;

[cpp] view plaincopy
@interface CustomStatusBar : UIWindow
{
UILabel *_messageLabel;
}

- (void)hideAnimation;

  • (void)showStatusMessage:(NSString *)message;
  • (void)hide;

- (void)show;

@end

- (void)showFromTopOffset:(CGFloat)topOffset;

接着,设置大小和系统状态栏一致,背景为黑色:
[cpp] view plaincopy
self.frame = [UIApplication sharedApplication].statusBarFrame;
self.backgroundColor = [UIColor blackColor];

- (void)showFromBottomOffset:(CGFloat)bottomOffset;

到这里,为了让自定义的状态栏可以让用户看到,还需要设置它的windowLevel。
在iOS中,windowLevel属性决定了UIWindow的显示层次。默认的windowLevel为UIWindowLevelNormal,即0.0。

@end

系统定义了三个层次如下,具体可参考官方文档:

@implementation JRToast

[cpp] view plaincopy
const UIWindowLevel UIWindowLevelNormal;
const UIWindowLevel UIWindowLevelAlert;
const UIWindowLevel UIWindowLevelStatusBar;
typedef CGFloat UIWindowLevel;

- (void)dealloc

为了能够覆盖系统默认的状态栏,我们把自定义的状态栏的windowLevel调高点:
[cpp] view plaincopy
self.windowLevel = UIWindowLevelStatusBar 1.0f;

{

最后,为显示信息和隐藏添加一点无伤大雅的动画:
[cpp] view plaincopy

[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:[UIDevice currentDevice]];

  • (void)showStatusMessage:(NSString *)message
    {
    self.hidden = NO;
    self.alpha = 1.0f;
    _messageLabel.text = @"";

    CGSize totalSize = self.frame.size;
    self.frame = (CGRect){ self.frame.origin, 0, totalSize.height };

    [UIView animateWithDuration:0.5f animations:^{
    self.frame = (CGRect){ self.frame.origin, totalSize };
    } completion:^(BOOL finished){
    _messageLabel.text = message;
    }];
    }

  • (void)hide
    {
    self.alpha = 1.0f;

    [UIView animateWithDuration:0.5f animations:^{
    self.alpha = 0.0f;
    } completion:^(BOOL finished){
    _messageLabel.text = @"";
    self.hidden = YES;
    }];;
    }

}

- (id)initWithText:(NSString *)text{

if (self = [super init]) {

_text = [text copy];

UIFont *font = [UIFont boldSystemFontOfSize:16];

CGSize textSize = [text boundingRectWithSize:CGSizeMake(280, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : font} context:nil].size;

UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, textSize.width 12, textSize.height 12)];

textLabel.backgroundColor = [UIColor clearColor];

textLabel.textColor = [UIColor whiteColor];

textLabel.textAlignment = NSTextAlignmentCenter;

textLabel.font = font;

textLabel.text = text;

textLabel.numberOfLines = 0;

_contentView = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, textLabel.frame.size.width, textLabel.frame.size.height)];

本文由1010cc时时彩标准版发布于操作系统,转载请注明出处:自定义状态栏代码详解,ios类似于安卓toast的唤醒

关键词:

上一篇:Directory域基础结构布局二,组计谋怎么样布署

下一篇:没有了