作為入門iOS開(kāi)發(fā)不久的小白, 每一次都是花大量時(shí)間去尋找別人寫好的東西來(lái)直接使用. 最近發(fā)現(xiàn)了一些很實(shí)用的 自定義控件. 感謝作者的開(kāi)源, 這里就分享給大家吧.方便好用,或許你可以試試
-
第一章 廣告展示類效果 ..................
-
第二章 提示類效果..................
-
第三章 列表類效果..................
-
第四章 側(cè)滑類效果..................
-
第五章 其他常用效果..................
-
第六章 玩玩swift..................
- ZJLeadingPageController 最簡(jiǎn)單的引導(dǎo)頁(yè)面demo. 使用可以是這樣的.
leading1.gif
// 如果是第一次安裝打開(kāi)App --- 顯示引導(dǎo)頁(yè)面
ZJLeadingPageController *leadController = [[ZJLeadingPageController alloc] initWithPagesCount:5 setupCellHandler:^(ZJLeadingPageCell *cell, NSIndexPath *indexPath) {
// 設(shè)置圖片
NSString *imageName = [NSString stringWithFormat:@"wangyiyun%ld",indexPath.row];
cell.imageView.image = [UIImage imageNamed:imageName];
// 設(shè)置按鈕屬性
[cell.finishBtn setTitle:@"立即體驗(yàn)" forState:UIControlStateNormal];
[cell.finishBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
} finishHandler:^(UIButton *finishBtn) {
NSLog(@"點(diǎn)擊了完成按鈕-----");
}];
// 自定義屬性
leadController.pageControl.pageIndicatorTintColor = [UIColor yellowColor];
leadController.pageControl.currentPageIndicatorTintColor = [UIColor purpleColor];
- ZJLaunchAd 展示啟動(dòng)廣告, 一個(gè)簡(jiǎn)單, 方便的啟動(dòng)廣告展示, 可以同時(shí)展示logo. 使用可能是下面這樣的.
launch.gif
ZJLaunchAdController *launchVc = [[ZJLaunchAdController alloc] initWithLaunchImage:nil setAdImageHandler:^(UIImageView *imageView) {
// 這里可以直接使用SDWebimage等來(lái)請(qǐng)求服務(wù)器提供的廣告圖片(SDWebimage會(huì)處理好gif圖片的顯示)
// 不過(guò)你需要注意選擇SDWebimage的緩存策略
imageView.image = [UIImage imageNamed:@"adImage"];
} finishHandler:^(ZJLaunchAdCallbackType callbackType) {
switch (callbackType) {
case ZJLaunchAdCallbackTypeClickAd:
// 點(diǎn)擊了廣告, 展示相應(yīng)的廣告即可
NSLog(@"點(diǎn)擊了廣告, 展示相應(yīng)的廣告即可");
break;
case ZJLaunchAdCallbackTypeShowFinish:
NSLog(@"展示廣告圖片結(jié)束, 可以進(jìn)入App");
break;
case ZJLaunchAdCallbackTypeClickSkipBtn:
NSLog(@"點(diǎn)擊了跳過(guò)廣告, 可以進(jìn)入App");
break;
}
}];
- ZJPPTView 可以玩出花樣的輪播器, 內(nèi)部不依賴第三方庫(kù), 使用簡(jiǎn)單, 可自定義輪播任何內(nèi)容. 圖片加載等類似tableView使用代理加載, 可自己選擇第三方庫(kù)來(lái)加載圖片等.
ppt.gif
_defaultPPT = [[ZJPPTViewDefault alloc] initWithDelegate:self];
_defaultPPT.pageControlPositon = ZJPPTViewPageControlPositionBottomCenter;
- (void)pptView:(ZJPPTViewOC *)pptView setUpPageCell:(UICollectionViewCell *)cell withIndex:(NSInteger)index {
if (pptView == _defaultPPT) {
ZJPPTViewDefaultCell *defaultCell = (ZJPPTViewDefaultCell *)cell;
// 可自定義文字屬性 ...
// defaultCell.textLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
// defaultCell.textLabel.textAlignment = NSTextAlignmentCenter;
// defaultCell.textLabel.textColor = [UIColor whiteColor];
defaultCell.textLabel.text = [NSString stringWithFormat:@" 這是第: %ld 頁(yè)", index];
// 設(shè)置圖片 網(wǎng)絡(luò)圖片, 可自由使用SDWebimage等來(lái)加載
if (index%2 == 0) {
UIImage *image = [UIImage imageNamed:@"1"];
defaultCell.imageView.image = image;
}
else {
UIImage *image = [UIImage imageNamed:@"2"];
defaultCell.imageView.image = image;
}
}
}
- ZJProgressHUD 自已寫個(gè)MBProgressHUD, 經(jīng)常使用MBProgressHUD? 不妨自己動(dòng)手來(lái)寫一個(gè), 反正也不難.
progressHUD.gif
// 顯示加載成功的圖片和文字提示, 1s后自動(dòng)隱藏
[ZJProgressHUD showSuccessWithStatus:@"加載成功!!" andAutoHideAfterTime:1.f];
// 顯示加載動(dòng)畫, 需要加載完成后調(diào)用hideHUD隱藏
[ZJProgressHUD showProgressWithStatus:@"正在努力加載中..."];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// 加載完后 移除提示框
[ZJProgressHUD hideHUD];
});
- ZJActionSheet 自定義UIActionSheet, 系統(tǒng)的UIActionSheet用著很不方便自定義, 比如修改文字的顏色, 大小, 以及顯示圖片等很不方便, 那么我們可以自己寫一個(gè), 然后類似下面這樣的效果.
actionSheet.gif
ZJActionSheetItem *item8 = [[ZJActionSheetItem alloc] initWithTitle:@"可以自定義所有item的字體顏色 大小等" image:nil handler:^(ZJActionSheetView *actionSheet) {
NSLog(@"點(diǎn)擊了收藏");
}];
ZJActionSheetItem *item9 = [[ZJActionSheetItem alloc] initWithTitle:@"可以設(shè)置actionSheet居中或者居下顯示" image:nil handler:^(ZJActionSheetView *actionSheet) {
NSLog(@"點(diǎn)擊了收藏");
}];
ZJActionSheetView *actionSheet = [[ZJActionSheetView alloc] initWithTitle:@"這是提示title" subtitle:@"這是詳細(xì)說(shuō)明文字,字體默認(rèn)14,可修改subtitleLabel" actionSheetItems:@[item1, item2, item3,item4,item5,item6,item7,item8,item9]];
// 顯示
[actionSheet show];
circleProgress.gif
self.progressView = [[ZJCircleProgressView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
// 背景色
self.progressView.trackBackgroundColor = [UIColor yellowColor];
// 進(jìn)度顏色
self.progressView.trackColor = [UIColor greenColor];
self.progressView.headerImage = [self drawImage];
// 開(kāi)始角度位置
// self.progressView.beginAngle =
// 自定義progressLabel的屬性...
self.progressView.progressLabel.textColor = [UIColor lightGrayColor];
// self.progressView.progressLabel.hidden = YES;
[self.view addSubview:self.progressView];
- (IBAction)slide:(id)sender {
UISlider *slider = (UISlider *)sender;
// 改變進(jìn)度
self.progressView.progress = slider.value;
self.pieProgressView.progress = slider.value;
}
contacts.gif
NSArray *testArray = @[@"ZeroJ", @"曾晶", @"你好", @"曾晶", @"曾晶" , @"曾晶" , @"曾晶" , @"曾晶" , @"曾晶" , @"曾晶" , @"曾晶", @"曾好", @"李涵", @"王丹", @"良好", @"124"];
NSMutableArray *contacts = [NSMutableArray arrayWithCapacity:testArray.count];
for (NSString *name in testArray) {
ZJContact *test = [ZJContact new];
test.name = name;
test.icon = [UIImage imageNamed:@"icon"];
[contacts addObject:test];
}
[self setupInitialAllDataArrayWithContacts:contacts];
citySelecte.gif
ZJCityViewControllerOne *vc = [[ZJCityViewControllerOne alloc] initWithDataArray:nil];
// __weak typeof(self) weakSelf = self;
[vc setupCityCellClickHandler:^(NSString *title) {
NSLog(@"選中的城市是: %@", title);
[ZJProgressHUD showStatus:[NSString stringWithFormat:@"選中的城市是: %@", title] andAutoHideAfterTime:1.f];
// [weakSelf.navigationController popViewControllerAnimated:YES];
}];
[self.navigationController showViewController:vc sender:nil];
pickerView.gif
[ZJUsefulPickerView showSingleColPickerWithToolBarText:@"單列數(shù)據(jù)" withData:@[@"objective-C", @"swift", @"iOS", @"iPad", @"iPod", @"mac", @"java", @"php", @"JavaScript"] withDefaultIndex:3 withCancelHandler:^{
NSLog(@"quxiaole -----");
} withDoneHandler:^(NSInteger selectedIndex, NSString *selectedValue) {
NSLog(@"%@---%ld", selectedValue, selectedIndex);
}];
// 省市區(qū)選擇
[ZJUsefulPickerView showCitiesPickerWithToolBarText:@"省市區(qū)選擇" withDefaultSelectedValues:@[@"四川", @"成都", @"郫縣"] withCancelHandler:^{
NSLog(@"quxiaole -----");
} withDoneHandler:^(NSArray *selectedValues) {
NSLog(@"%@---", selectedValues);
}];
drawer1.gif
drawer2.gif
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
ZJLeftViewController *left = [ZJLeftViewController new];
ZJCenterViewController *center = [ZJCenterViewController new];
UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:center];
ZJRightViewController *right = [ZJRightViewController new];
ZJDrawerController *drawer = [[ZJDrawerController alloc] initWithLeftController: left centerController:navi rightController:right];
// 背景圖片
drawer.backgroundImage = [UIImage imageNamed:@"1"];
// 動(dòng)畫類型
drawer.drawerControllerStyle = ZJDrawerControllerStyleParallaxSlide;
// 任何界面都能打開(kāi)抽屜
drawer.canOpenDrawerAtAnyPage = YES;
//...
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = drawer;
[self.window makeKeyAndVisible];
return YES;
}
swipeTableViewCell.gif
- (NSArray *)tableView:(UITableView *)tableView leftSwipeButtonsAtIndexPath:(NSIndexPath *)indexPath {
ZJSwipeButton *leftBtn = [[ZJSwipeButton alloc] initWithTitle:@"檢查1" image:nil onClickHandler:^(UIButton *swipeButton) {
NSLog(@"點(diǎn)擊了檢查1: --- %ld", indexPath.row);
[ZJProgressHUD showStatus:[NSString stringWithFormat:@"點(diǎn)擊了檢查1: --- %ld", indexPath.row] andAutoHideAfterTime:1];
}];
ZJSwipeButton *leftBtn1 = [[ZJSwipeButton alloc] initWithTitle:@"測(cè)試2" image:nil onClickHandler:^(UIButton *swipeButton) {
NSLog(@"點(diǎn)擊了測(cè)試2: --- %ld", indexPath.row);
[ZJProgressHUD showStatus:[NSString stringWithFormat:@"點(diǎn)擊了測(cè)試2: --- %ld", indexPath.row] andAutoHideAfterTime:1];
}];
return @[leftBtn,leftBtn1, leftBtn2,leftBtn3];
}
navigationController.gif
UIViewController *vc = [ViewController new];
ZJNavigationController *navi = [[ZJNavigationController alloc] initWithRootViewController:vc];
// 開(kāi)啟
[navi zj_enableFullScreenPop:YES];
qrScanner.gif
ZJQRScannerView *scanner = [ZJQRScannerView new];
scanner.frame = self.view.bounds;
[self.view addSubview:scanner];
// 開(kāi)始掃描
[scanner startScanning];
// 掃描完成
[scanner setScannerFinishHandler:^(ZJQRScannerView *scanner, NSString *resultString) {
// 掃描結(jié)束
NSLog(@"內(nèi)容是%@", resultString);
}];
tagView.gif
// 初始化第一個(gè)section數(shù)據(jù)
for (int i=0; i<20; i++) {
ZJTagItem *item = [ZJTagItem new];
item.name = [NSString stringWithFormat:@"選中--- %d",i];
[selectedItems addObject:item];
}
// 初始化第二個(gè)section數(shù)據(jù)
for (int i=0; i<40; i++) {
ZJTagItem *item = [ZJTagItem new];
item.name = [NSString stringWithFormat:@"未選中--- %d",i];
[unselectedItems addObject:item];
}
// 初始化
_tagView = [[ZJTagView alloc] initWithSelectedItems:selectedItems unselectedItems:unselectedItems];
lockView.gif
- (IBAction)deleteBtnOnClick:(id)sender {
if (![ZJLockViewController isAllreadySetPassword]) {
NSLog(@"未曾設(shè)置過(guò)密碼或者密碼已經(jīng)被刪除");
return;
}
// 初始化
ZJLockViewController *lock = [[ZJLockViewController alloc] initWithOperationType:ZJLockOperationTypeRemove delegate:self];
// 寬度
lock.lockView.pwdBtnSlideLength = 64.f;
// 線寬
lock.lockView.lineWidth = 8;
// 設(shè)置不同狀態(tài)的圖片
[lock.lockView setBtnImage:[UIImage imageNamed:@"normal"] forState:ZJLockButtonStateNormal];
[lock.lockView setBtnImage:[UIImage imageNamed:@"selected"] forState:ZJLockButtonStateSelected];
[lock.lockView setBtnImage:[UIImage imageNamed:@"error"] forState:ZJLockButtonStateError];
[self presentViewController:lock animated:YES completion:nil];
}
scrollPageView.gif
override func viewDidLoad() {
super.viewDidLoad()
// 這個(gè)是必要的設(shè)置
automaticallyAdjustsScrollViewInsets = false
var style = SegmentStyle()
// 縮放文字
style.scaleTitle = true
// 顏色漸變
style.gradualChangeTitleColor = true
// segment可以滾動(dòng)
style.scrollTitle = true
style.showExtraButton = true
let childVcs = setChildVcs()
let titles = childVcs.map { $0.title! }
let scrollPageView = ScrollPageView(frame: CGRect(x: 0, y: 64, width: view.bounds.size.width, height: view.bounds.size.height - 64), segmentStyle: style, titles: titles, childVcs: childVcs, parentViewController: self)
view.addSubview(scrollPageView)
}
refreshView.gif
let normalFooter = NormalAnimator.normalAnimator()
normalFooter.lastRefreshTimeKey = "exampleFooter1"
tableView.zj_addRefreshHeader(header, refreshHandler: {[weak self] in
/// 多線程中不要使用 [unowned self]
/// 注意這里的gcd是為了模擬網(wǎng)絡(luò)加載的過(guò)程, 在實(shí)際的使用中, 不需要這段gcd代碼, 直接在這里進(jìn)行網(wǎng)絡(luò)請(qǐng)求, 在請(qǐng)求完畢后, 調(diào)用分類方法, 結(jié)束刷新
dispatch_async(dispatch_get_global_queue(0, 0), {
for i in 0...50000 {
if i <= 10 {
self?.data.append(i)
}
/// 延時(shí)
print("加載數(shù)據(jù)中")
}
dispatch_async(dispatch_get_main_queue(), {
self?.tableView.reloadData()
/// 刷新完畢, 停止動(dòng)畫
self?.tableView.zj_stopHeaderAnimation()
})
})
})
這上面提到的所有的自定義控件都來(lái)自于這本書籍 感謝, 如有不當(dāng)?shù)牡胤? 請(qǐng)及時(shí)告知, 我會(huì)及時(shí)刪除.