Closed karthisiva closed 8 years ago
I ended with following code: Manuallu i added every UIElements objects to the array and checked when i clicked tab. view creation:
(UIView *)viewForTabAtIndex:(NSInteger)index {
UIView view=[[UIView alloc]init]; UIImageView img=[UIImageView new]; UILabel lblLine=[[UILabel alloc]init]; UILabel lbl=[[UILabel alloc]init]; lbl.font=[UIFont fontWithName:@"Myriad Pro" size:15]; img.tag=index; lbl.tag=index; if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { view.frame=CGRectMake(20, 0, 170, self.tabHeight); lblLine.frame=CGRectMake(160, 0,0.5,self.tabHeight); img.frame=CGRectMake(70, 15, 22, 22); lbl.frame=CGRectMake(43, 40, 80, 22); if (index==0) { [self.titleslbl removeAllObjects]; [self.titlesImage removeAllObjects]; }
}else{ if (IS_IPHONE_5) { view.frame=CGRectMake(0, 0, 90, self.tabHeight); img.frame=CGRectMake(38, 15, 22, 22); lbl.frame=CGRectMake(8, 40, 80, 22); lblLine.frame=CGRectMake(92, 0,0.5,self.tabHeight); } else if (IS_IPHONE_6){ view.frame=CGRectMake(0, 0, 98, self.tabHeight); img.frame=CGRectMake(37, 15, 22, 22); lblLine.frame=CGRectMake(98, 0,0.5,self.tabHeight); lbl.frame=CGRectMake(7, 40, 80, 22);
}
else if (IS_IPHONE_6_PLUS){
view.frame=CGRectMake(0, 0, 98, self.tabHeight);
img.frame=CGRectMake(37, 15, 22, 22);
lblLine.frame=CGRectMake(98, 0,0.5,self.tabHeight);
lbl.frame=CGRectMake(7, 40, 80, 22);
}
} if (index==rotationSelectedIndex){ img.image=[UIImage imageNamed:[self.selectedImages objectAtIndex:0]]; UIColor selectedFont=[CommonMethodClass pxColorWithHexValue:@"#A1CD46"]; lbl.textColor=selectedFont; } else{ img.image=[UIImage imageNamed:[self.images objectAtIndex:index]]; UIColor selectedFont=[CommonMethodClass pxColorWithHexValue:@"#8fa8d6"]; lbl.textColor=selectedFont; } [view addSubview:img]; lbl.textAlignment=NSTextAlignmentCenter; lbl.text=[NSString stringWithFormat:@"%@",[self.text objectAtIndex:index]]; [view addSubview:lbl]; if (index==5) { [lblLine setBackgroundColor:[UIColor clearColor]]; } else{ UIColor *backColor=[CommonMethodClass pxColorWithHexValue:@"#193167"]; [lblLine setBackgroundColor:backColor]; } [view addSubview:lblLine]; [self.titlesImage addObject:img]; [self.titleslbl addObject:lbl];
return view; }
To change selected image
}
-(void)setImg:(UIImageView )image setLbl:(UILabel )lbl { for (i=0; i<[self.titlesImage count]; i++) { UIImageView temp=[ self.titlesImage objectAtIndex:i]; UILabel selecedLbl=[self.titleslbl objectAtIndex:i]; if (image.tag==temp.tag) { image.image=[UIImage imageNamed:[self.selectedImages objectAtIndex:i]]; UIColor selectedFont=[CommonMethodClass pxColorWithHexValue:@"#A1CD46"]; lbl.textColor=selectedFont; } else { temp.image=[UIImage imageNamed:[self.images objectAtIndex:i]]; UIColor selectedFont=[CommonMethodClass pxColorWithHexValue:@"#8fa8d6"]; selecedLbl.textColor=selectedFont; } } }
my code create view
(UIView )viewForTabAtIndex:(NSInteger)index { UIView view=[[UIView alloc]init]; //view.backgroundColor=[UIColor orangeColor]; UIImageView *img=[UIImageView new]; view.frame=CGRectMake(10, 13, 60, self.tabHeight);
img.frame=CGRectMake(20, 15, 22, 22); img.image=[UIImage imageNamed:[self.images objectAtIndex:index]]; [view addSubview:img]; return view; }
i want to change images when i select tab..is there method for that?