CustomUITabBar with background color


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //header
  2.  
  3. #import <Foundation/Foundation.h>
  4.  
  5.  
  6. @interface CustomUITabBarController : UITabBarController {
  7.  
  8. }
  9.  
  10. @end
  11.  
  12. //implementation
  13.  
  14. #import "CustomUITabBarController.h"
  15.  
  16.  
  17. @interface UITabBarController (private)
  18. - (UITabBar *)tabBar;
  19. @end
  20.  
  21. @implementation CustomUITabBarController
  22.  
  23. -(float)rgbPercent:(int)rgb {
  24. int tmp = (rgb * 100) / 255;
  25. return [[NSString stringWithFormat:@".%i", tmp] floatValue];
  26. }
  27.  
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30.  
  31. CGRect frame = CGRectMake(0.0, 0.0, self.view.bounds.size.width, 48);
  32. UIView *v = [[UIView alloc] initWithFrame:frame];
  33. //UIColor *col = [UIColor colorWithRed:[self rgbPercent:0] green:[self rgbPercent:128] blue:1 alpha:1];
  34. UIColor *col = [UIColor colorWithRed:[self rgbPercent:128] green:1 blue:0 alpha:1];
  35. [v setBackgroundColor:col];
  36. [v setAlpha:0.5];
  37. [[self tabBar] addSubview:v];
  38. [v release];
  39.  
  40. }
  41. @end
  42.  
  43. //////////////////////////
  44. sample of use
  45. //////////////////////////
  46. CustomUITabBarController *tabBar = [[CustomUITabBarController alloc] init];
  47. [window addSubview:tabBar.view];

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.