2

フォントのサイズを変更しようとしているラベルとして、ナビゲーション バーのタイトルがあります。右バー ボタンを 2 つのボタンの配列として設定しました。タイトルのサイズを変更する代わりに、右のボタンの 1 つをノックオフします。

ここに私のコードがあります

- (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 です。また、左に揃えようとしましたが、うまくいきませんでした。次のコードは、右側に 2 つのボタンの配列を設定します。

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

タイトルのサイズを変更して、配列の 2 番目のボタンを覆わないようにするにはどうすればよいですか」

タイトル文字列がそれ以上の文字数の場合、フォント サイズが何かになるという if ステートメントを設定できますか。

4

0 に答える 0