The*_*low 17 objective-c interface-builder ios
我一直在寻找,但找不到答案.我正在开发一个iOS应用程序,并且有一个模式设置页面,只需点击一下按钮就会返回并返回一个segue.我想要实现的一个选项是配色方案设置.我真的想避免手动更改页面上每个元素的颜色.
Apple有这样的UIAppearance协议(所以我可以设置所有按钮的文本颜色等.他们的文档说:
注意:iOS在视图进入窗口时应用外观更改,但不会更改已在窗口中的视图的外观.要更改当前在窗口中的视图的外观,请从视图层次结构中删除该视图,然后将其放回.
我的问题是如何做到这一点.我试过没有运气调用viewWillAppear和setNeedsDisplay.
Dav*_*mot 22
尝试使用此代码段:
NSArray *windows = [UIApplication sharedApplication].windows;
for (UIWindow *window in windows) {
for (UIView *view in window.subviews) {
[view removeFromSuperview];
[window addSubview:view];
}
}
Run Code Online (Sandbox Code Playgroud)
http://snipplr.com/view/75259/refresh-uiappearance-after-application-loaded/
使用UIAppearance更改应用主题后,它对我来说非常适合
小智 8
具体来说,要获取当前视图及其超级视图,请尝试:
UIView *currentview = self.window.rootViewController.view;
UIView *superview = currentview.superview;
[currentview removeFromSuperview];
[superview addSubview:currentview];
Run Code Online (Sandbox Code Playgroud)
适合我.
请注意,最重要的答案将对您的系统键盘行为产生不利影响。
事实证明,UITextEffectsWindow每当显示键盘时,iOS都会在幕后创建一个带有类的新系统窗口。如果将其删除,则可能会对键盘行为产生负面影响。例如,除了导航控制器中的短暂闪烁外,输入的附件视图将与键盘分离,并且将不可见。
您可以通过使用其他检查来解决此问题,如下所示:
for window in UIApplication.shared.windows {
// Whenever a system keyboard is shown, a special internal window is created in application
// window list of type UITextEffectsWindow. This kind of window cannot be safely removed without
// having an adverse effect on keyboard behavior. For example, an input accessory view is
// disconnected from the keyboard. Therefore, a check for this class is needed. In case this class
// that is indernal is removed from the iOS SDK in future, there is a "fallback" class check on
// NSString class that always fails.
if !window.isKind(of: NSClassFromString("UITextEffectsWindow") ?? NSString.classForCoder()) {
window.subviews.forEach {
$0.removeFromSuperview()
window.addSubview($0)
}
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,它UITextEffectsWindow是内部的,将来可能会更改。这就是为什么我不使用来解开变量,!而是提供一个后备负NSString类(没有窗口类型属于此类NSString)的原因。
注意:对于简单的应用程序,您可能可以通过使用UIApplication.shared.keyWindow解决方法来生存。
对于Swift:
let windows = UIApplication.sharedApplication().windows
for window in windows {
for view in window.subviews {
view.removeFromSuperview()
window.addSubview(view)
}
}
Run Code Online (Sandbox Code Playgroud)
对于Swift 3.0.2:
for window in UIApplication.shared.windows {
for view in window.subviews {
view.removeFromSuperview()
window.addSubview(view)
}
// update the status bar if you change the appearance of it.
window.rootViewController?.setNeedsStatusBarAppearanceUpdate()
}
Run Code Online (Sandbox Code Playgroud)
尝试
[self.yourView removeFromSuperView];
[self addSubView:yourView];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13762 次 |
| 最近记录: |