我将导航栏标题作为标签,我正在尝试调整字体大小。我把右边的条形按钮设置为两个按钮的数组。而不是调整标题的大小,只需敲掉其中一个右键。
这是我的代码
- (void)setTitle:(NSString *)title
{
[super setTitle:title];
UILabel *titleView = (UILabel *)self.navigationItem.titleView;
if (!titleView) {
titleView = [[UILabel alloc] initWithFrame:CGRectZero];
titleView.backgroundColor = [UIColor clearColor];
titleView.font = [UIFont boldSystemFontOfSize:18.0];
titleView.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
titleView.textColor = [UIColor greenColor]; // Change to desired color
[titleView sizeToFit];
titleView.minimumScaleFactor = .33f;
CGRect frame = self.navigationItem.titleView.frame;
frame.origin .x = 10;
self.navigationItem.titleView = titleView;
self.navigationItem.titleView.frame = frame;
self.navigationItem.titleView = titleView;
}
titleView.text = title;
[titleView sizeToFit];
titleView.adjustsFontSizeToFitWidth = TRUE;
}
如您所见,我已将最大字体大小设置为18,最小值为6,最大大小为.33。我也尝试将它与左边对齐但是没有用。以下代码在右侧设置了一个包含两个按钮的数组。
buttonimage = [UIImage imageNamed:@"share icon1 Camera.png"];
UIBarButtonItem *saveButton =[[UIBarButtonItem alloc]
initWithImage:buttonimage
style:UIBarButtonItemStyleBordered
target:self
action:@selector(shareByActivity:)];
buttonimage2 = [UIImage imageNamed:@"mail icon sm Sound.png"];
UIBarButtonItem *soundButton =[[UIBarButtonItem alloc]
initWithImage:buttonimage2
style:UIBarButtonItemStyleBordered
target:self
action:@selector(shareByActivity2:)];
self.navigationItem.rightBarButtonItem = saveButton;
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:soundButton,saveButton, nil];
如何获得调整大小的标题,而不是覆盖数组的第二个按钮“
我可以设置一个if语句,如果标题字符串多于那么多字符,那么字体大小就是这样。