2

我有我的导航栏标题作为我试图调整字体大小的标签。我将右栏按钮设置为两个按钮的数组。而不是调整标题的大小,只是敲掉一个正确的按钮。

这是我的代码

- (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,即最大大小的 0.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 语句,如果标题字符串多于这么多字符,那么字体大小就是什么。

4

0 回答 0