網(wǎng)易或者頭條等新聞?lì)惖腶pp,首頁都是很多個(gè)可以滑動(dòng)的試圖,考慮到試圖不消失的情況,那么在試圖過多的時(shí)候如何做一些性能的優(yōu)化呢?
很顯然我們就聯(lián)想到了banner復(fù)用的機(jī)制,在這里就用UICollectionView來實(shí)現(xiàn)復(fù)用,達(dá)到優(yōu)化效果。
滾動(dòng).gif
- Segnment樣式選擇,基本上可以滿足UI的所有需求
@property (assign, nonatomic, getter=isShowCover) BOOL showCover;
/** 是否顯示滾動(dòng)條 默認(rèn)為NO*/
@property (assign, nonatomic, getter=isShowLine) BOOL showLine;
/** 是否縮放標(biāo)題 默認(rèn)為NO*/
@property (assign, nonatomic, getter=isScaleTitle) BOOL scaleTitle;
/** 是否滾動(dòng)標(biāo)題 默認(rèn)為YES 設(shè)置為NO的時(shí)候所有的標(biāo)題將不會(huì)滾動(dòng), 并且寬度會(huì)平分 和系統(tǒng)的segment效果相似 */
@property (assign, nonatomic, getter=isScrollTitle) BOOL scrollTitle;
/** segmentView是否有彈性 默認(rèn)為NO*/
@property (assign, nonatomic, getter=isSegmentViewBounces) BOOL segmentViewBounces;
/** 是否顏色漸變 默認(rèn)為NO*/
@property (assign, nonatomic, getter=isGradualChangeTitleColor) BOOL gradualChangeTitleColor;
/** 是否顯示附加的按鈕 默認(rèn)為NO*/
@property (assign, nonatomic, getter=isShowExtraButton) BOOL showExtraButton;
/** 內(nèi)容view是否能滑動(dòng) 默認(rèn)為YES*/
@property (assign, nonatomic, getter=isScrollContentView) BOOL scrollContentView;
/** 當(dāng)設(shè)置scrollTitle=NO的時(shí)候標(biāo)題會(huì)平分寬度, 如果你希望在滾動(dòng)的過程中cover或者scrollLine的寬度隨著變化設(shè)置這個(gè)屬性為YES 默認(rèn)為NO*/
@property (assign, nonatomic, getter=isAdjustCoverOrLineWidth) BOOL adjustCoverOrLineWidth;
/** 設(shè)置附加按鈕的背景圖片 默認(rèn)為nil*/
@property (strong, nonatomic) NSString *extraBtnBackgroundImageName;
/** 滾動(dòng)條的高度 默認(rèn)為2 */
@property (assign, nonatomic) CGFloat scrollLineHeight;
/** 滾動(dòng)條的顏色 */
@property (strong, nonatomic) UIColor *scrollLineColor;
/** 遮蓋的顏色 */
@property (strong, nonatomic) UIColor *coverBackgroundColor;
/** 遮蓋的圓角 默認(rèn)為14*/
@property (assign, nonatomic) CGFloat coverCornerRadius;
/** 遮蓋的高度 默認(rèn)為28*/
@property (assign, nonatomic) CGFloat coverHeight;
/** 標(biāo)題之間的間隙 默認(rèn)為15.0 */
@property (assign, nonatomic) CGFloat titleMargin;
/** 標(biāo)題的字體 默認(rèn)為14 */
@property (strong, nonatomic) UIFont *titleFont;
/** 標(biāo)題縮放倍數(shù), 默認(rèn)1.3 */
@property (assign, nonatomic) CGFloat titleBigScale;
/** 標(biāo)題一般狀態(tài)的顏色 */
@property (strong, nonatomic) UIColor *normalTitleColor;
/** 標(biāo)題選中狀態(tài)的顏色 */
@property (strong, nonatomic) UIColor *selectedTitleColor;
/** segmentVIew的高度, 這個(gè)屬性只在使用ZJScrollPageVIew的時(shí)候設(shè)置生效 */
@property (assign, nonatomic) CGFloat segmentHeight;```
###主要代碼:
//必要的設(shè)置, 如果沒有設(shè)置可能導(dǎo)致內(nèi)容顯示不正常
self.automaticallyAdjustsScrollViewInsets = NO;
ZJSegmentStyle *style = [[ZJSegmentStyle alloc] init];
//顯示滾動(dòng)條
style.showLine = YES;
// 顏色漸變
style.gradualChangeTitleColor = YES;
self.titles = @[@"新聞?lì)^條",
@"國(guó)際要聞",
@"體育",
@"中國(guó)足球",
@"汽車",
@"囧途旅游",
@"幽默搞笑",
@"視頻",
@"無厘頭",
@"美女圖片",
@"今日房?jī)r(jià)",
@"頭像",
];
// 初始化
ZJScrollPageView *scrollPageView = [[ZJScrollPageView alloc] initWithFrame:CGRectMake(0, 64.0, self.view.bounds.size.width, self.view.bounds.size.height - 64.0) segmentStyle:style titles:self.titles parentViewController:self delegate:self];
[self.view addSubview:scrollPageView];
###詳細(xì)參考demo[https://git.oschina.net/mrj_mrj/PageViewController.git]
?