一個類似于UISegmentControl的自定義控件:JRSegmentControl
一個類似于UISegmentControl的自定義控制,可以點擊和滑動來切換不同的選項。同時封裝了JRSegmentViewController可以方便集成類似于《貓眼電影》中的切換效果。
使用方法
(一)
#import "JRSegmentViewController.h"
初始化視圖控制器,并設置viewControllers屬性,如:
JRSegmentViewController *vc = [[JRSegmentViewController alloc] init]; vc.segmentBgColor = [UIColor colorWithRed:18.0f/255 green:50.0f/255 blue:110.0f/255 alpha:1.0f]; vc.indicatorViewColor = [UIColor whiteColor]; [vc setViewControllers:@[firstVC, secondVC, thirdVC]]; [vc setTitles:@[@"熱點", @"聚焦", @"推薦"]]; [self.navigationController pushViewController:vc animated:YES];
以上方法可以實現Demo中的效果,可參考Demo。
(二)
單獨使用 JRSegmentControl,使用方法類似 UISegmentControl
#import "JRSegmentControl"
JRSegmentControl *segment = [[JRSegmentControl alloc] initWithFrame:CGRectMake(20, 20, 180, 30) titles:@[@"熱點", @"聚焦", @"推薦"]]; segment.backgroundColor = [UIColor grayColor]; segment.indicatorViewColor = [UIColor whiteColor]; segment.delegate = self; // 遵守協議即可 [self.view addSubView:segment];
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!