JXTabMenuView.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // JXTabMenuView.m
  3. // sjvodios
  4. //
  5. // Created by daxiong on 13-4-17.
  6. //
  7. //
  8. #import "JXTabMenuView.h"
  9. #import "JXLabel.h"
  10. #import "JXTabButton.h"
  11. #import "JXBadgeView.h"
  12. @implementation JXTabMenuView
  13. @synthesize delegate,items,height,selected,imagesNormal,imagesSelect,onClick,backgroundImageName;
  14. - (id)initWithFrame:(CGRect)frame
  15. {
  16. self = [super initWithFrame:frame];
  17. if (self) {
  18. int width = JX_SCREEN_WIDTH/[items count];
  19. height = 49;
  20. self.backgroundColor = [UIColor clearColor];
  21. self.userInteractionEnabled = YES;
  22. // self.image = [UIImage imageNamed:backgroundImageName];
  23. _arrayBtns = [[NSMutableArray alloc]init];
  24. int i;
  25. for(i=0;i<[items count];i++){
  26. CGRect r = CGRectMake(width*i, 0, width, height);
  27. JXTabButton *btn = [JXTabButton buttonWithType:UIButtonTypeCustom];
  28. btn.iconName = [imagesNormal objectAtIndex:i];
  29. btn.selectedIconName = [imagesSelect objectAtIndex:i];
  30. btn.text = [items objectAtIndex:i];
  31. btn.textColor = HEXCOLOR(0x333333);
  32. btn.selectedTextColor = THEMECOLOR;
  33. btn.delegate = self.delegate;
  34. btn.onDragout = self.onDragout;
  35. // if(i==1)
  36. // btn.bage = @"1";
  37. btn.frame = r;
  38. btn.tag = i;
  39. if ((onClick != nil) && (delegate != nil))
  40. [btn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];
  41. [btn show];
  42. btn.lbBage.userInteractionEnabled = NO;
  43. [self addSubview:btn];
  44. [_arrayBtns addObject:btn];
  45. }
  46. UIView* line = [[UIView alloc]initWithFrame:CGRectMake(0,0,JX_SCREEN_WIDTH,LINE_WH)];
  47. line.backgroundColor = THE_LINE_COLOR;
  48. [self addSubview:line];
  49. // [line release];
  50. }
  51. return self;
  52. }
  53. -(void)dealloc{
  54. // [_arrayBtns release];
  55. // [items release];
  56. // [super dealloc];
  57. }
  58. -(void)onClick:(JXTabButton*)sender{
  59. [self unSelectAll];
  60. sender.selected = YES;
  61. self.selected = sender.tag;
  62. if(self.delegate != nil && [self.delegate respondsToSelector:self.onClick])
  63. [self.delegate performSelectorOnMainThread:self.onClick withObject:sender waitUntilDone:NO];
  64. }
  65. -(void)unSelectAll{
  66. for(int i=0;i<[_arrayBtns count];i++){
  67. ((JXTabButton*)[_arrayBtns objectAtIndex:i]).selected = NO;
  68. }
  69. selected = -1;
  70. }
  71. -(void)selectOne:(int)n{
  72. [self unSelectAll];
  73. if(n >= [_arrayBtns count])
  74. return;
  75. ((JXTabButton*)[_arrayBtns objectAtIndex:n]).selected=YES;
  76. selected = n;
  77. }
  78. -(void)setTitle:(int)n title:(NSString*)s{
  79. if(n >= [_arrayBtns count])
  80. return;
  81. [[_arrayBtns objectAtIndex:n] setTitle:s forState:UIControlStateNormal];
  82. }
  83. -(void)setBadge:(int)n title:(NSString*)s{
  84. if(n >= [_arrayBtns count])
  85. return;
  86. JXTabButton *btn = [_arrayBtns objectAtIndex:n];
  87. btn.bage = s;
  88. btn = nil;
  89. }
  90. @end