14

現在のプロジェクトを iOS 6 から iOS 7 に変換したいと考えています。iOS 6 ではプロジェクトは正常に動作していますが、iOS 7 ではナビゲーション バーの画像が正しく表示されません。

iOS 6 用のこのコード スニペットを使用しました。

UIImage *imgNav = [UIImage imageNamed:@"navigation.png"];
self.navigationController.navigationBar.frame = CGRectMake(0, 0, 320, 44);
[self.navigationController.navigationBar setBackgroundImage:imgNav forBarMetrics:
     UIBarMetricsDefault];

iOS 7 でナビゲーション バーの画像を設定するにはどうすればよいですか?

4

9 に答える 9

15

iOS 7 の場合:

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar.png"] forBarMetrics:UIBarMetricsDefault];
于 2013-06-28T09:46:15.173 に答える
4
if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] )
{

    UIImage *image = [UIImage imageNamed:@"navigation.png"];
    [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
}
于 2013-06-28T09:34:57.353 に答える
3

ストーリーボードの方法:

  1. イメージ ビューをストーリーボード シーンの下部のバーにドラッグします。
  2. シーン リストの左側にあるナビゲーション アイテムから、新しく作成されたイメージ ビューに Control キーを押しながらドラッグします。
  3. 画像ビューをクリックし、属性に画像を設定します。
于 2014-03-03T00:14:04.883 に答える
1

[[UINavigationBar の外観] setBackgroundImage:[UIImage imageNamed:@"navigation.png"] forBarMetrics:UIBarMetricsDefault];

ios7 ガイドに記載されているルールに従えば機能します。 • グラデーションのない単色が必要な場合は、1 x 1 ポイント イメージを作成します。• 垂直方向のグラデーションが必要な場合は、幅が 1 ポイントで、高さが UI 要素の背景の高さに一致する画像を作成します。• 繰り返しテクスチャの外観を提供する場合は、テクスチャの繰り返し部分の寸法と一致する寸法のイメージを作成する必要があります。• 繰り返しのないテクスチャ付きの外観を提供する場合は、UI 要素の背景領域の寸法と一致する寸法の静的画像を作成する必要があります。

詳細についてはリンクに従ってください:
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/ResizableImages.html#//apple_ref/doc/uid/TP40006556-CH30-SW1

于 2013-12-13T08:54:36.887 に答える
1

これだけやって..

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // This will set the backGround image for all the Navigation Bars

    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navigationBar"] forBarMetrics:UIBarMetricsDefault];



    return YES;
}
于 2014-06-25T09:15:34.393 に答える
0
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{


    [[UINavigationBar appearance] setTitleTextAttributes: @{
                                                            UITextAttributeTextColor: [UIColor whiteColor],
                                                            UITextAttributeTextShadowColor: [UIColor clearColor],
                                                            UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)],
                                                            UITextAttributeFont: [UIFont fontWithName:@"AppleGothic" size:20.0f]
                                                            }];

 if([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0)
    {


        [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navigatio_for_ios6"] forBarMetrics:UIBarMetricsDefault];

        [[UINavigationBar appearance] setTitleVerticalPositionAdjustment:0.0 forBarMetrics:UIBarMetricsDefault];
    }
else
    {
        [[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0x067AB5)];

        // Uncomment to change the color of back button
        [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

        // Uncomment to assign a custom backgroung image
        [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navigon_bg_ios7.png"] forBarMetrics:UIBarMetricsDefault];

        // Uncomment to change the back indicator image

        [[UINavigationBar appearance] setBackgroundColor:[UIColor whiteColor]];
        [[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@""]];

        // Uncomment to change the font style of the title

        NSShadow *shadow = [[NSShadow alloc] init];
        shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
        shadow.shadowOffset = CGSizeMake(0, 1);

        [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,shadow, NSShadowAttributeName,[UIFont fontWithName:@"HelveticaNeue-Bold" size:18.0], NSFontAttributeName, nil]];


        [[UINavigationBar appearance] setTitleVerticalPositionAdjustment:0.0 forBarMetrics:UIBarMetricsDefault];
    }



}
于 2014-06-10T05:36:03.117 に答える