新的ios5api:自定义UINavigationBar背景属性与简单的功能!!!

2021-02-24

栏目: ios ·

简介  这篇文章主要介绍了新的ios5api:自定义UINavigationBar背景属性与简单的功能!!!以及相关的经验技巧,文章约6397字,浏览量454,点赞数5,值得参考!

Here is a nice function you can use to implement a custom background for your UINavigation Bars

Simply make two images in photoshop:

32 x 32
44 x 44

and name them whatever you want.

put them in your iPhone project by dragging and dropping them from the desktop or another directory.

If need be check the Copy Group Destination files in folder line to add the two image files to your project.

Make sure you replace the two lines that create the UIImages with your image names


Copy And paste the function into your app delegate right above applicationDidFinishLaunchingWithOptions:

then simply call

[self customizeAppearance]; inside your app delegate and...

voila, enjoy :)
  1. - (void)customizeAppearance
  2. {
  3. // Create resizable images
  4. UIImage *gradientImage44 = [[UIImage imageNamed:@"gradient_textured_44"]
  5. resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  6. UIImage *gradientImage32 = [[UIImage imageNamed:@"gradient_textured_32"]
  7. resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  8.  
  9. // Set the background image for *all* UINavigationBars
  10. [[UINavigationBar appearance] setBackgroundImage:gradientImage44
  11. forBarMetrics:UIBarMetricsDefault];
  12. [[UINavigationBar appearance] setBackgroundImage:gradientImage32
  13. forBarMetrics:UIBarMetricsLandscapePhone];
  14.  
  15. // Customize the title text for *all* UINavigationBars
  16. [[UINavigationBar appearance] setTitleTextAttributes:
  17. [NSDictionary dictionaryWithObjectsAndKeys:
  18. [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
  19. UITextAttributeTextColor,
  20. [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
  21. UITextAttributeTextShadowColor,
  22. [NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
  23. UITextAttributeTextShadowOffset,
  24. [UIFont fontWithName:@"Arial-Bold" size:0.0],
  25. UITextAttributeFont,
  26. nil]];
  27.  
  28. }

以上就是本文的全部内容,希望对大家的学习有所帮助,本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

相关文章

如何快速自定义修改新的打印线宽?

php MU插件|新的自定义帖子类型

php 使用模板注册新的自定义帖子类型

php Wordpress:注册新的自定义帖子类型

全代码实现WordPress分类目录和标签添加新的自定义字段

text WP =添加新的自定义程序部分(字段)

php 将新的自定义帖子类型添加到Wordpress

php 向WPB页面构建器添加新的自定义元素