Layout iOS 7上的自定义布局将元素渲染为高
我对iOS 7上的自定义布局有问题。所有内容都显得太高,即在导航栏下。在iOS 6上,即使在使用iOS 7 SDK编译时,它也像一个魅力 下面我发布了用于初始化和布局视图的代码。我不使用Interface Builder,我更愿意不使用。谢谢你的帮助Layout iOS 7上的自定义布局将元素渲染为高,layout,view,ios7,Layout,View,Ios7,我对iOS 7上的自定义布局有问题。所有内容都显得太高,即在导航栏下。在iOS 6上,即使在使用iOS 7 SDK编译时,它也像一个魅力 下面我发布了用于初始化和布局视图的代码。我不使用Interface Builder,我更愿意不使用。谢谢你的帮助 - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.documentTitle = [UI
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.documentTitle = [UITextField new];
self.documentExtension = [UILabel new];
self.documentTitle.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Document title"];
self.documentTitle.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize] + 1];
self.documentTitle.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
self.documentTitle.borderStyle = UITextBorderStyleRoundedRect;
self.documentTitle.returnKeyType = UIReturnKeyDone;
self.documentTitle.keyboardType = UIKeyboardTypeDefault;
self.documentExtension.text = @".pdf";
self.documentExtension.backgroundColor = [UIColor clearColor];
[self addSubview:self.documentTitle];
[self addSubview:self.documentExtension];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
UIEdgeInsets padding = UIEdgeInsetsMake(12, 10, 12, 10);
CGRect layoutRect = UIEdgeInsetsInsetRect(self.bounds, padding);
CGPoint p = layoutRect.origin;
CGSize tmpSize;
CGFloat tfSpaceHorizontal = 6;
CGFloat tfSpaceVertical = 6;
CGSize tmpSizeDocumentExtension = [self.documentExtension sizeThatFits:CGSizeMake(CGRectGetWidth(layoutRect), 1000)];
tmpSize = CGSizeMake(
roundf((CGRectGetWidth(layoutRect) - tfSpaceHorizontal - tmpSizeDocumentExtension.width)),
32
);
self.documentTitle.frame = CGRectMake(
p.x, p.y,
tmpSize.width,
tmpSize.height
);
p.x += tmpSize.width + tfSpaceHorizontal;
CGFloat addedHeight = roundf(tmpSize.height/2 - tmpSizeDocumentExtension.height/2);
addedHeight = addedHeight > 0 ? addedHeight : 0;
p.y += addedHeight;
self.documentExtension.frame = CGRectMake(
p.x,
p.y,
tmpSizeDocumentExtension.width,
tmpSizeDocumentExtension.height
);
}
在iOS 7中,每个视图控制器都使用全屏布局,因此坐标系从状态栏下开始,因此在定位视图时请注意 这在苹果的报告中提到过