9

「Now Playing」はUIBarButtonItemの1行です。「Now」が一番上、「Playing」が一番下のように、2 行に分けて配置する必要があります。次のコード行を書きました。

UIBarButtonItem *flipButton = [[UIBarButtonItem alloc]

                              initWithTitle:@"Now Playing" 

                              style:UIBarButtonItemStyleBordered 

                              target:self 

                              action:@selector(flipView)];


    self.navigationItem.rightBarButtonItem = flipButton;  

だから、「Now Playing」の間に改行を入れたい。だから私を助けてください。

4

4 に答える 4

10

はい、できます。やり方はかなり簡単です。複数行ボタンを作成して使用します。「トリック」は、複数行が好きになるように titleLabel numberOfLines プロパティを設定することです。

UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
button.titleLabel.numberOfLines = 0;
[button setTitle:NSLocalizedString(@"Now\nPlaying", nil) forState:UIControlStateNormal];
[button sizeToFit];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];

カスタムのボタンタイプを指定すると、すべてを構成することが期待されます...選択された状態など、ここには示されていません。

于 2013-10-17T02:54:36.227 に答える
4
- (void)createCustomRightBarButton_
{
    UILabel * addCustomLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 64, 25)] autorelease];
    addCustomLabel.text =@"Now\nPlaying";
    addCustomLabel.textColor = [UIColor whiteColor];
    addCustomLabel.font = [UIFont boldSystemFontOfSize:11];
    addCustomLabel.numberOfLines = 2;
    addCustomLabel.backgroundColor = [UIColor clearColor];
    addCustomLabel.textAlignment = UITextAlignmentCenter;

    CGSize size = addCustomLabel.bounds.size;

    UIGraphicsBeginImageContext(size);      
    CGContextRef context = UIGraphicsGetCurrentContext();       
    [addCustomLabel.layer renderInContext: context];
    CGImageRef imageRef = CGBitmapContextCreateImage(context);
    UIImage * img = [UIImage imageWithCGImage: imageRef];
    CGImageRelease(imageRef);
    CGContextRelease(context);

    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithImage:img
                                                                           style:UIBarButtonItemStyleBordered 
                                                                          target:self 
                                                                          action:@selector(flipView)]
                                              autorelease];
}
于 2012-03-07T13:08:13.593 に答える
0

UIButtonをバーボタン内でcustomViewとしてホストし(バーボタンアイテムcustomViewを設定するか、UIBarButtonItemの上に直接ドラッグすることができます)、アウトレットとして接続してから実行します。

-(void) viewDidLoad
{
  //...
  self.customButton.titleLabel.numberOfLines = 2;
  self.customButton.suggestionsButton.titleLabel.lineBreakMode = UILineBreakModeWordWrap;
  self.customButton.suggestionsButton.titleLabel.textAlignment = UITextAlignmentCenter;
}

私の場合は

ここに画像の説明を入力してください

于 2013-01-15T09:13:35.380 に答える
0

ここに画像の説明を入力 ここに画像の説明を入力

自分で 2 つの PNG 画像を作成しましたが、見栄えがします。

UIImage *img = [UIImage imageNamed:@"nowplaying.png"];
UIBarButtonItem *nowPlayingButtonItem = [[[UIBarButtonItem alloc] initWithImage:img style:UIBarButtonItemStyleBordered target:delegate action:@selector(presentNowPlayingMovie)] autorelease];
于 2013-11-21T14:17:20.787 に答える