专栏名称: Adrenine
iOS开发
目录
相关文章推荐
哈尔滨日报  ·  哈尔滨市人大常委会任职名单 ·  18 小时前  
龙江市场监管  ·  视频 | 让我们共同践行 珍惜每一粒粮食 ·  23 小时前  
骏景农业  ·  黑龙江未来三天天气预报 ·  2 天前  
51好读  ›  专栏  ›  Adrenine

iOS实战之使用View实现导航栏下的滑动菜单

Adrenine  · 掘金  ·  · 2017-12-13 08:46

正文

请到「今天看啥」查看全文


(!self.myTitleArray) { self.myTitleArray=@[@ "新闻" ,@ "NBA" ,@ "财经" ,@ "科技" ,@ "软件公司" ,@ "健身" ,@ "优秀文摘" ]; } self.items=[[NSMutableArray alloc]init]; self.itemsWidth=[[NSArray alloc]init]; //初始化滚动 if (!self.myScrollView) { self.myScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, NAV_TAB_BAR_Width, NAV_TAB_BAR_HEIGHT)]; self.myScrollView.backgroundColor=[UIColor redColor]; self.myScrollView.showsHorizontalScrollIndicator = NO; self.myScrollView.showsVerticalScrollIndicator = NO; [self.view addSubview:self.myScrollView]; } //赋值跟计算滚动 _itemsWidth = [self getButtonsWidthWithTitles:self.myTitleArray]; CGFloat contentWidth = [self contentWidthAndAddNavTabBarItemsWithButtonsWidth:_itemsWidth]; self.myScrollView.contentSize = CGSizeMake(contentWidth, 0); self.currentIndex=0; } /** * @brief 计算宽度 * * @param titles < #titles description#> * * @ return < #return value description#> */ - (NSArray *)getButtonsWidthWithTitles:(NSArray *)titles; { NSMutableArray *widths = [@[] mutableCopy]; _selectedTitlesWidth = 0; for (NSString *title in titles) { CGSize size = [title boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : TABBAR_TITLE_FONT} context:nil].size; CGFloat eachButtonWidth = size.width + 20.f; _selectedTitlesWidth += eachButtonWidth; NSNumber *width = [NSNumber numberWithFloat:eachButtonWidth]; [widths addObject:width]; } if





请到「今天看啥」查看全文