2

I have my navigation bar title as a label that I am trying to resize the font. I have the right bar button set up as an array of two buttons. Instead of resizing the title just knocks off one of the right buttons.

here is my code

- (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;
}

as you can see I have set the max font size to 18 and the min to 6 being .33 of the max size. I have also tried to align it to the left but that didn't work. The following code set up an array of two button on the right side.

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];

how can I get the title to resize and not cover the second button of the array"

Can I set an if statement that if the title string is more that so many characters then the font size is something.

user1114881
  • 731
  • 1
  • 12
  • 25

0 Answers0