前言
最近做了一個(gè)類(lèi)似網(wǎng)易新聞的滾動(dòng)視圖, 大致效果如下:

效果圖.gif
使用方法
self.view.backgroundColor = [UIColor whiteColor];
NSArray *vcs = [self setupChildVcAndTitle];
CGRect frame = self.view.frame;
if (self.navigationController) {
frame.origin.y = 64;
}
WYPageView *page = [[WYPageView alloc] initWithFrame:frame childVcs:vcs parentViewController:self pageConfig:_config];
[self.view addSubview:page];
self.pageView = page;
支持:
- 自定義指示器寬高
- 自定義指示器滾動(dòng)效果
- 可完全自定義指示器樣式
- 支持標(biāo)題字體顏色漸變、縮放效果
- 自定義標(biāo)題高度
文件介紹:
WYPageConfig:WYPageView的配置類(lèi),初始化可以傳入該對(duì)象,可配置titleView和contentView的各種屬性,詳細(xì)配置可以查看WYPageConfig .h文件WYPageTitleView: 標(biāo)題視圖WYPageConetentView: 內(nèi)容視圖
WYPageConfig的部分配置信息
/**
指示器類(lèi)型 默認(rèn)'WYPageTitleIndicatorViewStyleDownLine'
*/
@property (nonatomic , assign) WYPageTitleIndicatorViewStyle indicatorStyle;
/**
指示器的位置 默認(rèn)在下面 'WYPageTitleIndicatorViewPositionStyleBottom'
*/
@property (nonatomic , assign) WYPageTitleIndicatorViewPositionStyle indicatorPositionStyle;
/**
指示器高度 默認(rèn)'2'
*/
@property (nonatomic , assign) CGFloat indicatorViewHeight;
/**
指示器顏色 默認(rèn)紅色 如果是自定義指示器 需要自己設(shè)置指示器背景顏色
*/
@property (nonatomic , strong) UIColor *indicatorViewColor;
/**
指示器寬度是否等于標(biāo)題item的寬度 默認(rèn)'YES' YES: 相等 NO: 不相等,可以手動(dòng)設(shè)置'indicatorViewWidth'的值
*/
@property (nonatomic , assign) BOOL indicatorViewWidthEqualToItemWidth;
/**
指示器的寬度 默認(rèn)'30' 在'indicatorViewWidthEqualToItemWidth'為'NO'時(shí)有效 如果是自定義指示器 會(huì)優(yōu)先使用其frame
*/
@property (nonatomic , assign) CGFloat indicatorViewWidth;
/**
指示器的滾動(dòng)效果 默認(rèn)'WYIndicatorScrollAnimationValue1'
*/
@property (nonatomic , assign) WYIndicatorScrollAnimation indicatorViewScrollAnimation;
/**
標(biāo)題之間的間隔 默認(rèn)'15'
*/
@property (nonatomic , assign) CGFloat titleMargin;
/**
標(biāo)題字體大小 默認(rèn)'14'
*/
@property (nonatomic , strong) UIFont *titleFont;
/**
標(biāo)題是否可以縮放 默認(rèn)NO
*/
@property (nonatomic , assign) BOOL canZoomTitle;
/**
字體縮放比例 默認(rèn)'1.3'
*/
@property (nonatomic , assign) CGFloat titleZoomMultiple;
/**
標(biāo)題正常狀態(tài)下字體顏色
*/
@property (nonatomic , strong) UIColor *normalTitleColor;
/**
標(biāo)題選中狀態(tài)下字體顏色
*/
@property (nonatomic , strong) UIColor *selectedTitleColor;
具體可以點(diǎn)擊我的Github下載查看具體Demo,歡迎各位大神提供建議意見(jiàn)。
寫(xiě)在最后:
WYPageConetentView開(kāi)始的時(shí)候是使用的collectionView,但是最后發(fā)現(xiàn)使用collectionView時(shí)子控制器的生命周期不正確。譬如在滑動(dòng)結(jié)束后,不僅會(huì)加載當(dāng)前vc,還會(huì)加載下個(gè)vc的viewDidLoad方法,而且因?yàn)?code>cell的重用機(jī)制,控制器的viewDidApper和viewDidDisapper也會(huì)出現(xiàn)錯(cuò)亂。我想要的效果是在下一個(gè)vc出現(xiàn)的時(shí)候才會(huì)開(kāi)啟vc的生命周期,所以最后改用scrollView來(lái)替代了collectionView,如果有大神有更好的方法,請(qǐng)多多指教~