WZDraggableSwitchHeaderView Documentation
Welcome to the documentation for WZDraggableSwitchHeaderView, an iOS library that provides a draggable switch-like header view.
Installation
Follow the steps below to install WZDraggableSwitchHeaderView in your iOS project:
- Open your terminal.
- Navigate to your project directory.
- Run the following command to install the library via Cocoapods:
pod 'WZDraggableSwitchHeaderView'
Usage
To use WZDraggableSwitchHeaderView in your project, follow the steps below:
- Import the library in the desired view controller:
// Objective-C
#import <WZDraggableSwitchHeaderView/WZDraggableSwitchHeaderView.h>
// Swift
import WZDraggableSwitchHeaderView
- Create an instance of WZDraggableSwitchHeaderView:
// Objective-C
WZDraggableSwitchHeaderView *headerView = [[WZDraggableSwitchHeaderView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 200)];
// Swift
let headerView = WZDraggableSwitchHeaderView(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height: 200))
- Configure the header view’s properties:
// Objective-C
headerView.delegate = self;
headerView.title = @"Draggable Header";
headerView.contentViewController = yourContentViewController;
// Swift
headerView.delegate = self
headerView.title = "Draggable Header"
headerView.contentViewController = yourContentViewController
- Add the header view to your view controller’s view:
// Objective-C
[self.view addSubview:headerView];
// Swift
view.addSubview(headerView)
Delegate Methods
WZDraggableSwitchHeaderView provides the following delegate methods:
// Objective-C
- (void)headerViewDidBeginDragging:(WZDraggableSwitchHeaderView *)headerView;
- (void)headerViewDidEndDragging:(WZDraggableSwitchHeaderView *)headerView;
- (void)headerView:(WZDraggableSwitchHeaderView *)headerView didScrollToPercentage:(CGFloat)percentage;
- (void)headerView:(WZDraggableSwitchHeaderView *)headerView didSwitchToIndex:(NSInteger)index;
// Swift
func headerViewDidBeginDragging(_ headerView: WZDraggableSwitchHeaderView)
func headerViewDidEndDragging(_ headerView: WZDraggableSwitchHeaderView)
func headerView(_ headerView: WZDraggableSwitchHeaderView, didScrollToPercentage percentage: CGFloat)
func headerView(_ headerView: WZDraggableSwitchHeaderView, didSwitchToIndex index: Int)
Implement these methods in your view controller to handle the corresponding events.
Predefined Styles
WZDraggableSwitchHeaderView offers the following predefined styles:
- Default style
- Customizable style
To use a predefined style, simply set it on the header view:
// Objective-C
headerView.style = WZDraggableSwitchHeaderViewStyleDefault;
// Swift
headerView.style = .default
Customization
If you prefer a custom style for your header view, you can customize various properties:
- Switch color
- Switch selected color
- Title font
- Title color
- Background color
Example:
// Objective-C
headerView.switchColor = [UIColor blueColor];
headerView.switchSelectedColor = [UIColor redColor];
headerView.titleFont = [UIFont systemFontOfSize:16];
headerView.titleColor = [UIColor blackColor];
headerView.backgroundColor = [UIColor whiteColor];
// Swift
headerView.switchColor = .blue
headerView.switchSelectedColor = .red
headerView.titleFont = UIFont.systemFont(ofSize: 16)
headerView.titleColor = .black
headerView.backgroundColor = .white
Conclusion
Congratulations! You have successfully integrated WZDraggableSwitchHeaderView into your iOS project. Feel free to explore more features and customize as per your requirements.