CustomTabbar.h
#import <UIKit/UIKit.h>
#import "UIView+NibLoading.h"
@class CustomTabBar;
@protocol CustomTabBarDelegate
@required
- (void)setTabIndex:(int)index;
@end
@interface CustomTabBar : UIView {
//id<CustomTabBarDelegate> delegate;
}
@property (nonatomic, strong)IBOutlet UIImageView *imgTabBackGround;
@property (nonatomic, strong)IBOutlet UIButton *btnOne, *btnTwo, *btnThree;
@property(nonatomic, strong)IBOutlet UILabel *lblone;
@property(nonatomic, strong)IBOutlet UILabel *lbltwo;
@property(nonatomic, strong)IBOutlet UILabel *lblthree;
@property(nonatomic, strong)IBOutlet UIImageView *imgOne;
@property(nonatomic, strong)IBOutlet UIImageView *imgTwo;
@property(nonatomic, strong)IBOutlet UIImageView *imgThree;
@property (nonatomic, strong) id<CustomTabBarDelegate> delegate;
-(IBAction)onClickbtnOne:(id)sender;
-(IBAction)onClickbtnTwo:(id)sender;
-(IBAction)onClickbtnThree:(id)sender;
CustomTabbar.m
#import "CustomTabBar.h"
#import <QuartzCore/QuartzCore.h>
#import "AppDelegate.h"
#import "TabBarController.h"
@implementation CustomTabBar
AppDelegate *appDelegate;
#pragma mark -
#pragma mark - init methods
-(id) initWithFrame:(CGRect)frame {
if(self == [super initWithFrame:frame])
{
appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
self = (CustomTabBar *)[CustomTabBar loadInstanceFromNib:self];
self.frame = frame;
//self.hidden = TRUE;
[self setBackgroundColor:[UIColor clearColor]];
[self onClickbtnOne:nil];
}
return self;
}
#pragma mark -
#pragma mark - Actions
-(IBAction)onClickbtnOne:(id)sender{
appDelegate.tabBarController.selectedIndex=0;
[delegate setTabIndex:0];
[self setTabBar];
[self.lblOne setFont:[UIFont boldSystemFontOfSize:10.0]];
[self.lblOne setTextColor:[UIColor whiteColor]];
[self.imgOne setImage:[UIImage imageNamed:@"btnOne_on"]];
}
-(IBAction)onClickbtnTwo:(id)sender{
appDelegate.tabBarController.selectedIndex=1;
[delegate setTabIndex:1];
[self setTabBar];
[self.lblTwo setFont:[UIFont boldSystemFontOfSize:10.0]];
[self.lblTwo setTextColor:[UIColor whiteColor]];
[self.imgTwo setImage:[UIImage imageNamed:@"btnTwo_on"]];
}
-(IBAction)onClickbtnThree:(id)sender{
appDelegate.tabBarController.selectedIndex=2;
[delegate setTabIndex:2];
[self setTabBar];
[self.lblThree setFont:[UIFont boldSystemFontOfSize:10.0]];
[self.lblThree setTextColor:[UIColor whiteColor]];
[self.imgThree setImage:[UIImage imageNamed:@"btnThree_on"]];
}
-(void)setTabBar{
[self.lblOne setFont:[UIFont systemFontOfSize:10.0]];
[self.lblOne setTextColor:[UIColor lightGrayColor]];
[self.lblTwo setFont:[UIFont systemFontOfSize:10.0]];
[self.lblTwo setTextColor:[UIColor lightGrayColor]];
[self.lblThree setFont:[UIFont systemFontOfSize:10.0]];
[self.lblThree setTextColor:[UIColor lightGrayColor]];
[self.imgOne setImage:[UIImage imageNamed:@"btnZ"]];
[self.imgTwo setImage:[UIImage imageNamed:@"btnS"]];
[self.imgThree setImage:[UIImage imageNamed:@"btnY"]];
}
@end
Category Class :-
#import "UIView+NibLoading.h"
@implementation UIView (NibLoading)
+(UIView*) loadInstanceFromNib:(id)fileOwner {
UIView *result = nil;
//NSLog(@"[self class] >>>> %@",NSStringFromClass([self class]));
NSArray* elements = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:fileOwner options: nil];
for (id anObject in elements) {
if ([anObject isKindOfClass:[self class]]) {
result = anObject;
break;
}
}
return result;
}
@end
-(void)addCustomTabbar
{
if(self.objCustomTabBar == nil)
self.objCustomTabBar=[[CustomTabBar alloc]initWithFrame:CGRectMake(0, ((isiPhone5) ? 498.0:410.0), 321, 70)];
[self.window addSubview:self.objCustomTabBar];
[self.window bringSubviewToFront:self.objCustomTabBar];
}
No comments:
Post a Comment