diff --git a/LTNavigationBar/UINavigationBar+Awesome.m b/LTNavigationBar/UINavigationBar+Awesome.m index 10adb5b..e1d3a62 100644 --- a/LTNavigationBar/UINavigationBar+Awesome.m +++ b/LTNavigationBar/UINavigationBar+Awesome.m @@ -28,7 +28,14 @@ - (void)lt_setBackgroundColor:(UIColor *)backgroundColor { if (!self.overlay) { [self setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; - self.overlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds) + 20)]; + + //解决 iPhone X 适配问题 + CGFloat toolHeight = 20; + if ([[UIScreen mainScreen] bounds].size.height >= 812.0f) { + //说明是iPhone X + toolHeight = 44; + } + self.overlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds) + toolHeight)]; self.overlay.userInteractionEnabled = NO; self.overlay.autoresizingMask = UIViewAutoresizingFlexibleWidth; // Should not set `UIViewAutoresizingFlexibleHeight` [[self.subviews firstObject] insertSubview:self.overlay atIndex:0];