【问题标题】:how to change UINavigationBar light如何更改 UINavigationBar 灯
【发布时间】:2013-05-08 09:46:35
【问题描述】:

我对 iOS 开发还很陌生,这是我第一次在这里设计样式。

在任何人说话之前我就知道下面的代码会改变颜色

self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.169 green:0.373 blue:0.192 alpha:0.9];

我想做的是改变导航栏中的灯光。当前是从上到下渐变的默认设置。但我想做的是改变它,让它像图片一样发光,只在中间。

我不知道最好是使用图片还是使用 xcode 绘制灯光会更好。主要是由于内存消耗和效率。我的猜测是画光是最好的选择,我只需要知道怎么做。

我尝试搜索此内容,但可能是我缺乏 iOS 开发知识,这使我无法找到正确的教程或代码示例以了解如何执行此操作。

感谢任何帮助。

这是另一个光照分布与默认 UINavBar 不同的例子。我真的想知道他们是用图片还是用 xCode 绘制的

【问题讨论】:

    标签: ios objective-c cocoa-touch uinavigationbar


    【解决方案1】:

    最好为条形图使用自定义图像,而不是“绘制”发光。

    【讨论】:

      【解决方案2】:

      你可以使用自定义图片,试试这个:

      [[UINavigationBar appearance] setBackgroundImage:yourImage forBarMetrics:UIBarMetricsDefault]
      

      在您的应用委托中添加此代码,它作为全局设置工作,所有导航栏都将被设置

      【讨论】:

        【解决方案3】:
        - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
        {     
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
            self.imgBackgroundView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
         [self.window addSubview:self.imgBackgroundView];
            [self addCustomNavigationController];
        [self addCustomNavigationController];
        }
        
        - (void)addCustomNavigationController
        {
            self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
            self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
            if ([[UINavigationBar class] respondsToSelector:@selector(appearance)])
            {
                [[UINavigationBar appearance] setBackgroundImage:[self getImageFromResource:@"topbar"] forBarMetrics:UIBarMetricsDefault];
                [[UINavigationBar appearance] setTitleTextAttributes:
                 [NSDictionary dictionaryWithObjectsAndKeys:
                  [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
                  UITextAttributeTextColor,
                  [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
                  UITextAttributeTextShadowColor,
                  [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                  UITextAttributeTextShadowOffset,
                  [UIFont fontWithName:@"HelveticaNeue-Bold" size:18.0],
                  UITextAttributeFont,
                  nil]];
            }
            [[NSUserDefaults standardUserDefaults] setObject:@"Login" forKey:@"randomView"];
        }
        
        - (UIImage*)getImageFromResource:(NSString*)imageName
        {
            return [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageName ofType:@"png"]];
        }
        

        【讨论】:

          【解决方案4】:

          您好,请使用 iOS5 和 iOS6 的外观 [[UIBarButtonItem 外观] setTintColor:[UIColor colorWithRed:0.08 green:0.72 blue:0.78 alpha:1]];

          【讨论】:

            【解决方案5】:

            另一种解决方案是在 NavigationBar 上添加一个 UIButton。

            从属性检查器或使用设置它的 Shows touch on highlight 属性

            [buttonGlow setShowsTouchWhenHighlighted:YES];
            

            viewDidLoad:

            [buttonGlow setHighlighted:YES];
            

            【讨论】:

              【解决方案6】:

              我需要的是PaintCode,这是使用与普通图像一样具有内存效率的代码绘制和图像的最佳方式,但考虑到在代码中它允许对图像进行高度自定义。请参阅 here 了解有关绘图图像内存的帖子

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 2011-05-18
                • 1970-01-01
                • 1970-01-01
                • 2015-08-31
                • 2011-11-29
                • 1970-01-01
                • 2016-06-30
                • 2010-10-28
                相关资源
                最近更新 更多