2

私はプラグインしており、sizeWithFont: メソッドを使用してレイアウトを適切に並べる必要がありますが、カスタム フォントでは機能しないようです。それを機能させる方法はありますか、それとも別の方法を使用できますか?

私はこれにかなり困惑しています。どんな助けでも大歓迎です。

4

2 に答える 2

1

sizeWithFont は間違いなく機能するはずですが、問題が発生している場合は回避策があります。テキストを UITextView に配置してレイアウトに追加し、実際のテキスト サイズを取得してそれに応じて調整することができます。私のプロジェクトのサンプルコードは次のとおりです。

     // Put in the title in
    self.titleView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 195, 195)];
    self.titleView.font = [UIFont fontWithName:@"Bliss Pro" size:20.0];
    [self addSubview:self.titleView];

    self.titleView.text = @"Add your text here";

    // Now get the actual size of the text and resize the title view's frame
    CGRect frame = self.titleView.frame;
    frame.size.height = self.titleView.contentSize.height;
    self.titleView.frame = frame;

少しハックですが、確かに機能します。

于 2012-07-24T05:24:59.840 に答える
-1
#define kFontSize 14.0    //modify your font size
CGSize size = [yourView sizeWithFont:[UIFont boldSystemFontOfSize:kFontSize]];
于 2012-07-24T05:46:45.200 に答える