6

UINavigationBariOSに収まるようにタイトル テキストを縮小することは可能ですか。

(自動レイアウトのない縦長の iPhone アプリの場合)。

タイトルバーを動的に設定していますが、テキストが長すぎる場合があり、現時点では省略記号で切り取っています。

つまり、「これは...」

代わりにテキストを縮小したいと思います。

4

3 に答える 3

10

独自のタイトル ビューを作成して作成できます。

このようなもの:

- (void)viewDidLoad
{
    [super viewDidLoad];

  //Do any additional setup after loading the view, typically from a nib.
     UILabel *titleLabelView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 40)]; //<<---- Actually will be auto-resized according to frame of navigation bar;
    [titleLabelView setBackgroundColor:[UIColor clearColor]];
    [titleLabelView setTextAlignment: NSTextAlignmentCenter];
    [titleLabelView setTextColor:[UIColor whiteColor]];
    [titleLabelView setFont:[UIFont systemFontOfSize: 27]]; //<<--- Greatest font size
    [titleLabelView setAdjustsFontSizeToFitWidth:YES]; //<<---- Allow shrink
     // [titleLabelView setAdjustsLetterSpacingToFitWidth:YES];  //<<-- Another option for iOS 6+
    titleLabelView.text = @"This is a Title";

    navigationBar.topItem.titleView = titleLabelView;

    //....
}

お役に立てれば。

于 2013-07-25T14:20:15.430 に答える
2
Xcode 7.1 - Swift 2.0


//Adding Title Label
        var navigationTitlelabel = UILabel(frame: CGRectMake(0, 0, 200, 21))
        navigationTitlelabel.center = CGPointMake(160, 284)
        navigationTitlelabel.textAlignment = NSTextAlignment.Center
        navigationTitlelabel.textColor  = UIColor.whiteColor()
        navigationTitlelabel.text = "WORK ORDER"
        self.navigationController!.navigationBar.topItem!.titleView = navigationTitlelabel
于 2016-01-04T08:53:48.623 に答える