将0.5点高度子视图添加到iOS7中未显示的UINavigationBar
我有一个类继承自将0.5点高度子视图添加到iOS7中未显示的UINavigationBar,ios,objective-c,ios7,uiview,uinavigationbar,Ios,Objective C,Ios7,Uiview,Uinavigationbar,我有一个类继承自UINavigationBar,我想添加一条分隔线作为其子视图,以分隔导航栏和导航内容 线的高度定义如下 #define SEPERATOR_LINE_HEIGHT (1.0f / [UIScreen mainScreen].scale) 我的代码: @interface MyPopNavigationBar : UINavigationBar @end @implementation MyPopNavigationBar { UIView *separatorLin
UINavigationBar
,我想添加一条分隔线作为其子视图,以分隔导航栏和导航内容
线的高度定义如下
#define SEPERATOR_LINE_HEIGHT (1.0f / [UIScreen mainScreen].scale)
我的代码:
@interface MyPopNavigationBar : UINavigationBar
@end
@implementation MyPopNavigationBar {
UIView *separatorLine;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.clipsToBounds = YES;
self.translucent = NO;
separatorLine = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(self.bounds) - SEPERATOR_LINE_HEIGHT, CGRectGetWidth(self.bounds), SEPERATOR_LINE_HEIGHT)];
separatorLine.backgroundColor = [UIColor redColor];
separatorLine.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
[self addSubview:separatorLine];
}
return self;
}
这在iOS 6和iOS 8(全部为视网膜)中都能正常工作,但在iOS 7(视网膜)中我看不到我的separatorLine
iOS 6和8:
iOS 7:
此外,当我试图将分隔线高度设置为精确的1时,它会显示在所有iOS版本中
separatorLine = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(self.bounds) - 1, CGRectGetWidth(self.bounds), 1)];
怎么了?我自己解决了这个问题。这是因为
自动重定尺寸磁盘的故障是一个类似的问题。