0
我加入一個標題爲UIToolbar(新iPad)用下面的代碼過低:的UIBarButtonItem的垂直對齊是在橫向模式下
- (void)setupToolbarItems {
if (!toolbarItems) {
UIBarButtonItem *flexSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 386.0, 20.0)];
titleLabel.autoresizingMask = (UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth);
titleLabel.textColor = [UIColor whiteColor];
titleLabel.text = @"Hello";
titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:20.0];
titleLabel.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.5];
titleLabel.shadowOffset = CGSizeMake(0.0, -1.0);
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.backgroundColor = [UIColor clearColor];
UIBarButtonItem *titleLabelItem = [[UIBarButtonItem alloc] initWithCustomView:titleLabel];
toolbarItems = [[NSArray alloc] initWithObjects:flexSpacer, titleLabelItem, flexSpacer, nil];
[titleLabel release];
[flexSpacer release];
[titleLabelItem release];
}
[self setItems:self.toolbarItems animated:NO];
}
一切正常的肖像,但在橫向模式下的標籤太遠了。 UIBarButtonItem不是一個視圖,所以我沒有辦法從我的代碼中調整它的位置,據我所知...我該如何解決這個問題?
肖像:
景觀:
這似乎沒有做任何事情。它仍然和以前一樣 – FeifanZ
實際上,在重新添加XIB和清理之後,它現在起作用了。謝謝! – FeifanZ