我正在使用以下代码向UIToolbar(iPad)添加标题:
- (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不是一个视图,所以我无法从我的代码中调整它的位置,据我所知......我该如何解决这个问题?
<小时/>
人像:
风景:
答案 0 :(得分:0)
将UIViewAutoresizingFlexibleHeight
添加到titleView。你不会让它缩小标签。