美文网首页
自定义TabBar

自定义TabBar

作者: 李毅然 | 来源:发表于2016-04-11 20:57 被阅读0次

-(instancetype)initWithArray:(NSArray*)array{

self= [superinit];

if(self) {

CGRectoldTabBarFrame =self.tabBar.frame;

UIView*myView = [[UIViewalloc]initWithFrame:oldTabBarFrame];

[self.viewaddSubview:myView];

CGFloatwidth = [UIScreenmainScreen].bounds.size.width/array.count;

for(NSIntegeri =0; i

UIButton* button = [UIButtonbuttonWithType:(UIButtonTypeSystem)];

[buttonsetTitle:[arrayobjectAtIndex:i]forState:(UIControlStateNormal)];

button.frame=CGRectMake(width * i,0, width, oldTabBarFrame.size.height);

button.tag=1000+ i;

button.backgroundColor= [UIColorblackColor];

[buttonsetTitleColor:[UIColorwhiteColor]forState:(UIControlStateNormal)];

[myViewaddSubview:button];

[buttonaddTarget:selfaction:@selector(didClickButton:)forControlEvents:(UIControlEventTouchUpInside)];

}

}

returnself;

}

-(void)didClickButton:(UIButton*)button{

self.selectedIndex= button.tag-1000;

}

相关文章

网友评论

      本文标题:自定义TabBar

      本文链接:https://www.haomeiwen.com/subject/hzmilttx.html