国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS中關于UIWindow和statusbar的設置問題

2019-10-21 18:47:56
字體:
來源:轉載
供稿:網友

最近在做開發時要做一個類似于UIAlertView的控件,做法是創建一個基于UIView的類,在里面進行自定義控件的設置,為了盡量模仿UIAlertView,在這個類里面創建了一個新的UIWindow并將self顯示到這個window上。

由于app中statusbar中的內容為白色的,新創建的window就會改變statusbar的狀態,不能得到我們想要的結果,為了避開一系列其他錯誤,設置statusbar的顏色時采用

- (UIStatusBarStyle)preferredStatusBarStyle?- (void)setNeedsStatusBarAppearanceUpdate?

這兩個方法,你沒看錯,這兩個方法是UIViewController的方法,那么跟UIView有什么關系呢,不錯,這里我們是想給UIWindow設置rootViewController,在這個rootViewController中寫這兩個方法并做一些其他的設置,這樣控件能顯示在rootViewController中,statusbar也是我們想要的狀態。

上代碼(demo部分代碼):

// TestView.h#import@interface TestView : UIView@property (nonatomic, strong) NSString *clickTitle;?- (void)show;@end// TestView.m?#import "TestView.h"@implementation TestView{  UIWindow *window;  UIButton *clickBtn;}- (void)makeWindow{  window = [[UIWindow alloc] init];  window.windowLevel = UIWindowLevelStatusBar + 1;  window.backgroundColor = [UIColor clearColor];  [window makeKeyAndVisible];  TestVC *rootVC = [[TestVCalloc] init];  rootVC.view.backgroundColor = [UIColorcolorWithRed:0green:0blue:0alpha:0.5];  UINavigationController *navi = [[UINavigationControlleralloc]initWithRootViewController:rootVC];  window.rootViewController = navi;  navi.navigationBarHidden = YES;  self.frame = CGRectMake(0, 0, window.frame.size.width - 40, 80);  self.center = window.center;  [rootVC.view addSubview:self];}- (instancetype)initWithFrame:(CGRect)frame{  if (self = [super initWithFrame:frame]) {    clickBtn = [UIButton buttonWithType:UIButtonTypeCustom];  }  returnself;}- (NSString *)clickTitle{  if (!_clickTitle) {    _clickTitle = @"clicks";  }  return_clickTitle;}- (void)show{  [clickBtn setTitle:self.clickTitleforState:UIControlStateNormal];  [selfmakeWindow];}// TestVC.m#import "TestVC.h"@interfaceTestVC ()@end@implementation TestVC- (void)viewDidLoad {  [super viewDidLoad];  // Do any additional setup after loading the view.  [self setNeedsStatusBarAppearanceUpdate];}- (UIStatusBarStyle)preferredStatusBarStyle{  return UIStatusBarStyleLightContent;}

?代碼很簡單,卻是我為了達到這一效果想了很久,感覺會有更簡單的辦法,以后繼續研究。

以上所述是小編給大家介紹的iOS中關于UIWindow和statusbar的設置問題,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對VEVB武林網網站的支持!


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 柏乡县| 吉木萨尔县| 中山市| 永修县| 吉木萨尔县| 合水县| 怀集县| 自治县| 宁河县| 苏州市| 巩义市| 营山县| 商丘市| 荣昌县| 临邑县| 文成县| 盱眙县| 西乡县| 乐昌市| 竹山县| 沙湾县| 庐江县| 岑巩县| 文成县| 英山县| 会宁县| 定襄县| 金门县| 右玉县| 旌德县| 华容县| 大兴区| 大名县| 金昌市| 昌邑市| 宜州市| 苍梧县| 化隆| 即墨市| 平阴县| 姚安县|