- (
void
) configNvItem{
UISegmentedControl * segmentontrol = [[ UISegmentedControl alloc ] initWithItems : @[ @" 晒场 " , @" 活动 " ] ];
segmentontrol. tintColor = [ UIColor whiteColor ];
segmentontrol. frame = CGRectMake ( 0 , 0 , 200 , 34 );
NSDictionary *normalAttribute = [ NSDictionary dictionaryWithObjectsAndKeys :[ UIFont systemFontOfSize : 19 ], NSFontAttributeName , [ UIColor redColor ], NSForegroundColorAttributeName , nil ];
NSDictionary *selectedAttribute = [ NSDictionary dictionaryWithObjectsAndKeys :[ UIFont systemFontOfSize : 19 ], NSFontAttributeName , kThemeColor , NSForegroundColorAttributeName , nil ];
[segmentontrol setTitleTextAttributes :normalAttribute forState : UIControlStateNormal ];
[segmentontrol setTitleTextAttributes :selectedAttribute forState : UIControlStateSelected ];
[segmentontrol addTarget : self action : @selector (changeShowContent:) forControlEvents : UIControlEventValueChanged ];
[segmentontrol setSelectedSegmentIndex : 0 ];
[ self showContentAtType : 0 ];
self . navigationItem . titleView = segmentontrol;
}
#pragma mark -User Interaction
- ( void ) changeShowContent:( UISegmentedControl *) segmentControl{
[ self showContentAtType :segmentControl. selectedSegmentIndex ];
}
#pragma mark -Public Methods
/**
* 根据活动类型切换显示数据
* @param type, 0: 晒场 1: 活动
*/
- ( void ) showContentAtType:( NSInteger ) type{
if (type == 0 ) {
[ self . view addSubview : self . showViewController . view ];
[ self . showViewController didMoveToParentViewController : self ];
[ self . dynamicViewController willMoveToParentViewController : nil ];
[ self . dynamicViewController . view removeFromSuperview ];
} else {
[ self . view addSubview : self . dynamicViewController . view ];
[ self . dynamicViewController didMoveToParentViewController : self ];
[ self . showViewController willMoveToParentViewController : nil ];
[ self . showViewController . view removeFromSuperview ];
}
}
#pragma mark -Access
#pragma mark 延迟初始化
- ( MFFriendViewController *) showViewController{
if (! _showViewController ) {
_showViewController = [[ MFFriendViewController alloc ] init ];
[ self addChildViewController : _showViewController ];
self . showViewController . view . frame = CGRectMake ( self . showViewController . view . frame . origin . x , self . view . frame . origin . y + 80 , self . view . frame . size . width , self . showViewController . view . frame . size . height - 100 );
}
return _showViewController ;
}
- ( MFMineViewController *) dynamicViewController{
if (! _dynamicViewController ) {
_dynamicViewController = [[ MFMineViewController alloc ] init ];
[ self addChildViewController : _dynamicViewController ];
self . dynamicViewController . view . frame = CGRectMake ( self . dynamicViewController . view . frame . origin . x , self . view . frame . origin . y + 80 , self . view . frame . size . width , self . dynamicViewController . view . frame . size . height - 100 );
}
return _dynamicViewController ;
UISegmentedControl * segmentontrol = [[ UISegmentedControl alloc ] initWithItems : @[ @" 晒场 " , @" 活动 " ] ];
segmentontrol. tintColor = [ UIColor whiteColor ];
segmentontrol. frame = CGRectMake ( 0 , 0 , 200 , 34 );
NSDictionary *normalAttribute = [ NSDictionary dictionaryWithObjectsAndKeys :[ UIFont systemFontOfSize : 19 ], NSFontAttributeName , [ UIColor redColor ], NSForegroundColorAttributeName , nil ];
NSDictionary *selectedAttribute = [ NSDictionary dictionaryWithObjectsAndKeys :[ UIFont systemFontOfSize : 19 ], NSFontAttributeName , kThemeColor , NSForegroundColorAttributeName , nil ];
[segmentontrol setTitleTextAttributes :normalAttribute forState : UIControlStateNormal ];
[segmentontrol setTitleTextAttributes :selectedAttribute forState : UIControlStateSelected ];
[segmentontrol addTarget : self action : @selector (changeShowContent:) forControlEvents : UIControlEventValueChanged ];
[segmentontrol setSelectedSegmentIndex : 0 ];
[ self showContentAtType : 0 ];
self . navigationItem . titleView = segmentontrol;
}
#pragma mark -User Interaction
- ( void ) changeShowContent:( UISegmentedControl *) segmentControl{
[ self showContentAtType :segmentControl. selectedSegmentIndex ];
}
#pragma mark -Public Methods
/**
* 根据活动类型切换显示数据
* @param type, 0: 晒场 1: 活动
*/
- ( void ) showContentAtType:( NSInteger ) type{
if (type == 0 ) {
[ self . view addSubview : self . showViewController . view ];
[ self . showViewController didMoveToParentViewController : self ];
[ self . dynamicViewController willMoveToParentViewController : nil ];
[ self . dynamicViewController . view removeFromSuperview ];
} else {
[ self . view addSubview : self . dynamicViewController . view ];
[ self . dynamicViewController didMoveToParentViewController : self ];
[ self . showViewController willMoveToParentViewController : nil ];
[ self . showViewController . view removeFromSuperview ];
}
}
#pragma mark -Access
#pragma mark 延迟初始化
- ( MFFriendViewController *) showViewController{
if (! _showViewController ) {
_showViewController = [[ MFFriendViewController alloc ] init ];
[ self addChildViewController : _showViewController ];
self . showViewController . view . frame = CGRectMake ( self . showViewController . view . frame . origin . x , self . view . frame . origin . y + 80 , self . view . frame . size . width , self . showViewController . view . frame . size . height - 100 );
}
return _showViewController ;
}
- ( MFMineViewController *) dynamicViewController{
if (! _dynamicViewController ) {
_dynamicViewController = [[ MFMineViewController alloc ] init ];
[ self addChildViewController : _dynamicViewController ];
self . dynamicViewController . view . frame = CGRectMake ( self . dynamicViewController . view . frame . origin . x , self . view . frame . origin . y + 80 , self . view . frame . size . width , self . dynamicViewController . view . frame . size . height - 100 );
}
return _dynamicViewController ;
}