自定义Tabbar封装
来源:互联网 发布:通达信股票行情软件 编辑:程序博客网 时间:2024/05/21 09:08
// 1. CustomTabbar.h#import <UIKit/UIKit.h>@interface CutomTabBar : UIView@property (nonatomic,strong) NSArray *images;@property (nonatomic,strong) NSArray *seletedImages;@property (nonatomic,strong) NSArray *titles;@property (nonatomic,strong) NSArray *buttons;/** 初始化CutomTabBar对象 */+ (id)tabBarWithImages:(NSArray *)images seletedImages:(NSArray *)seletedImages titles:(NSArray *)titles;@end// 2. CustomTabbar.m@interface CutomTabBar ()@end@implementation CutomTabBar+ (id)tabBarWithImages:(NSArray *)images seletedImages:(NSArray *)seletedImages titles:(NSArray *)titles { CutomTabBar *tabBar = [[CutomTabBar alloc] init]; for (int i = 0; i < titles.count; i++) { UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [tabBar addSubview:button]; // frame CGFloat buttonW = 375.0f/titles.count; CGFloat buttonX = buttonW * i; CGFloat buttonY = 0; CGFloat buttonH = 49; button.frame = CGRectMake(buttonX, buttonY, buttonW, buttonH); // titles [button setTitle:titles[i] forState:UIControlStateNormal]; [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal]; [button setTitleColor:[UIColor redColor] forState:UIControlStateSelected]; button.titleLabel.font = [UIFont systemFontOfSize:10.0f]; button.titleEdgeInsets = UIEdgeInsetsMake(60, -30, 0, 0); // images NSString *imageName = [images objectAtIndex:i]; NSString *selectedImageName = [seletedImages objectAtIndex:i]; [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal]; [button setImage:[UIImage imageNamed:selectedImageName] forState:UIControlStateSelected]; button.imageEdgeInsets = UIEdgeInsetsMake(10, 17, 0, 0); // 事件 [button addTarget:tabBar action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; button.tag = i; } return tabBar;}- (void)drawRect:(CGRect)rect { UIImage *image = [UIImage imageNamed:@"导航栏"];// [image drawAtPoint:CGPointZero];// [image drawAsPatternInRect:rect]; [image drawInRect:rect];}#pragma mark - 按钮点击事件- (void)buttonAction:(UIButton *)button { for (UIButton *btn in self.subviews) { btn.selected = NO; } NSLog(@"index - %ld", button.tag);}- (void)willMoveToSuperview:(UIView *)newSuperview { self.frame = CGRectMake(0, 667-64, 375, 64); self.backgroundColor = [UIColor whiteColor]; }@end
0 0
- 自定义Tabbar封装
- iOS自定义封装tabBar
- 自定义tabbar的基本封装
- 完美封装 tabBar 自定义加号按钮
- Swift - 自定义tabbar的封装
- 自定义TabBar
- 自定义TabBar
- 自定义Tabbar
- 自定义tabbar
- 自定义tabbar
- 自定义 TabBar
- 自定义TabBar
- 自定义tabBar
- 自定义TabBar
- 自定义TabBar
- 自定义Tabbar
- 自定义tabbar
- 自定义 TabBar
- Android 5.1 Contacts源码分析(三):Contacts模块Fargment结构
- FastCGI简介
- 我的Docker学习之旅<三>
- httppost 远程服务器返回错误: (400) 错误的请求错误
- hdu 5456 Matches Puzzle Game(记忆化搜索)
- 自定义Tabbar封装
- ios 内存小结
- 链路层介绍,转载自实验楼
- ERROR ITMS-90086 有效处理方式
- 当幸福来敲门
- 网赛 HDU 5444 Elven Postman
- Nginx与PHP(FastCGI)的安装、配置与优化
- 由appcampat 的思考
- linux动态链接