当前位置: 首页 > 科技观察

顶部滑动菜单FDSlideBar

时间:2023-03-22 14:11:07 科技观察

源码介绍:FDSlideBar是一个顶部滑动菜单,如网易、腾讯新闻常用样式。该控件支持自定义颜色、字体和其他样式。菜单切换流畅,体验不错。在下半部分的内容显示上纠结了很久,最终还是选择了UITableView来实现,很好的解决了ScrollView的内存问题,获得了不错的原生滑动效果。测试环境:Xcode6.2、iOS6.0或以上源码截图:源码片段:FDSlideBar*sliderBar=[[FDSlideBaralloc]init];sliderBar.backgroundColor=[UIColorcolorWithRed:0/255.0green:128/255.0blue:128/255.0alpha:1.0];//InitthetitlesofalltheitemsliderBar.itemsTitle=@[@"新闻",@"视频",@"上海",@"娱乐",@"体育NBA",@"财经",@"科技",@"Social",@"Military",@"Fashion",@"Car",@"Game",@"Image",@"Stock"];//SetsomestyletotheslideBarsliderBar.itemColor=[UIColorwhiteColor];sliderBar.itemSelectedColor=[UIColororangeColor];sliderBar.sliderColor=[UIColororangeColor];//Addthecallbackwiththeactionthatanyitembeselected[sliderBarslideBarItemSelectedCallback:^(NSUIntegeridx){[self.tableViewscrollToRowAtIndexPath:[NSIndexPathindexPathForRow:idxinSection:0]atScrollPosition:UITableViewScrollPositionTopanimated:NO];}];[self.viewaddSubview:sliderBar];_slideBar=sliderBar;//frameoftableView,注意width和height属性rtyCGRectframe=CGRectMake(0,0,CGRectGetMaxY(self.view.frame)-CGRectGetMaxY(self.slideBar.frame),CGRectGetWidth(self.view.frame));self.tableView=[[UITableViewalloc]initWithFrame:frame];[self.viewaddSubview:self.tableView];//RegisterthecustomcellUINib*nib=[UINibnibWithNibName:@"TableViewCell"bundle:nil];[self.tableViewregisterNib:nibforCellReuseIdentifier:@"ContentCell"];//SetthetableViewcenterinthebottomofview.soafterrotating,itshowsrightlyself.tableView.center=CGPointMake(CGRectGetWidth(self.view.frame)*0.5,CGRectGetHeight(self.view.frame)*0.5+CGRectGetMaxY(self.slideBar.frame)*0.5);self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;//RotatethetableView90angleanticlockwiseself.tableView.transform=CGAffineTransformMakeRotation(-M_PI_2);self.tableView.showsVerticalScrollIndicator=NO;self.tableView.pagingEnabled=YES;self.tableView.dataSource=self;self.tableView.delegate=self;-(UITableViewCell*)tableView:(UITableView*)tableViewcellForRowAtIndexPath:(NSIndexPath*)indexPath{TableViewCell*cell=[self.tableViewdequeueReusableCellWithIdentifier:@"ContentCell"];//Rotatethecell'scontent90angleclockwisetoshowthemrightlycell.contentView.transform=CGAffineTransformMakeRotation(M_PI_2);cell.text=self.slideBar.itemsTitle[indexPath.row];returncell;}下载地址:http://down.51cto.com/data/2068577

最新推荐
猜你喜欢