Skip to content

Commit

Permalink
add new feature red point
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenYilong committed Jun 14, 2017
1 parent c3b7bb0 commit a6c3be7
Show file tree
Hide file tree
Showing 17 changed files with 443 additions and 58 deletions.
2 changes: 1 addition & 1 deletion CYLTabBarController.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "CYLTabBarController"
s.version = "1.12.1"
s.version = "1.13.0"
s.summary = "Highly customizable tabBar and tabBarController for iOS"
s.description = "CYLTabBarController is iPad and iPhone compatible. Supports landscape and portrait orientations and can be used inside UINavigationController."
s.homepage = "https://github.com/ChenYilong/CYLTabBarController"
Expand Down
12 changes: 12 additions & 0 deletions CYLTabBarController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
9A1559DE1CB6D56500CAB1AF /* CYLDetailsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A1559D51CB6D56500CAB1AF /* CYLDetailsViewController.m */; };
9A1559DF1CB6D56500CAB1AF /* CYLSameCityViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A1559D71CB6D56500CAB1AF /* CYLSameCityViewController.m */; };
9A1559E41CB6EB1F00CAB1AF /* CYLPlusButtonSubclass.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A1559E31CB6EB1F00CAB1AF /* CYLPlusButtonSubclass.m */; };
9A474B5A1EF03D1B0020D132 /* UITabBarItem+CYLTabBarControllerExtention.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A474B591EF03D1B0020D132 /* UITabBarItem+CYLTabBarControllerExtention.m */; };
9A474B5D1EF1586C0020D132 /* UIControl+CYLTabBarControllerExtention.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A474B5C1EF1586C0020D132 /* UIControl+CYLTabBarControllerExtention.m */; };
9A474C0F1EEFCCE200560ED1 /* UIView+CYLTabBarControllerExtention.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A474C0E1EEFCCE200560ED1 /* UIView+CYLTabBarControllerExtention.m */; };
9AE667131C800085001DED12 /* UIViewController+CYLTabBarControllerExtention.m in Sources */ = {isa = PBXBuildFile; fileRef = 9AE667121C800085001DED12 /* UIViewController+CYLTabBarControllerExtention.m */; };
9AE942E71BDC933E00354519 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9AE942CB1BDC933E00354519 /* LaunchScreen.xib */; };
Expand Down Expand Up @@ -43,6 +45,10 @@
9A1559D71CB6D56500CAB1AF /* CYLSameCityViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CYLSameCityViewController.m; sourceTree = "<group>"; };
9A1559E21CB6EB1F00CAB1AF /* CYLPlusButtonSubclass.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CYLPlusButtonSubclass.h; sourceTree = "<group>"; };
9A1559E31CB6EB1F00CAB1AF /* CYLPlusButtonSubclass.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CYLPlusButtonSubclass.m; sourceTree = "<group>"; };
9A474B581EF03D1B0020D132 /* UITabBarItem+CYLTabBarControllerExtention.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UITabBarItem+CYLTabBarControllerExtention.h"; sourceTree = "<group>"; };
9A474B591EF03D1B0020D132 /* UITabBarItem+CYLTabBarControllerExtention.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UITabBarItem+CYLTabBarControllerExtention.m"; sourceTree = "<group>"; };
9A474B5B1EF1586C0020D132 /* UIControl+CYLTabBarControllerExtention.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIControl+CYLTabBarControllerExtention.h"; sourceTree = "<group>"; };
9A474B5C1EF1586C0020D132 /* UIControl+CYLTabBarControllerExtention.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIControl+CYLTabBarControllerExtention.m"; sourceTree = "<group>"; };
9A474C0D1EEFCCE200560ED1 /* UIView+CYLTabBarControllerExtention.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+CYLTabBarControllerExtention.h"; sourceTree = "<group>"; };
9A474C0E1EEFCCE200560ED1 /* UIView+CYLTabBarControllerExtention.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+CYLTabBarControllerExtention.m"; sourceTree = "<group>"; };
9A5B29111D3475BC009E1BEE /* CYLConstants.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CYLConstants.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -207,6 +213,10 @@
9AE667121C800085001DED12 /* UIViewController+CYLTabBarControllerExtention.m */,
9A474C0D1EEFCCE200560ED1 /* UIView+CYLTabBarControllerExtention.h */,
9A474C0E1EEFCCE200560ED1 /* UIView+CYLTabBarControllerExtention.m */,
9A474B581EF03D1B0020D132 /* UITabBarItem+CYLTabBarControllerExtention.h */,
9A474B591EF03D1B0020D132 /* UITabBarItem+CYLTabBarControllerExtention.m */,
9A474B5B1EF1586C0020D132 /* UIControl+CYLTabBarControllerExtention.h */,
9A474B5C1EF1586C0020D132 /* UIControl+CYLTabBarControllerExtention.m */,
9A5B29111D3475BC009E1BEE /* CYLConstants.h */,
);
path = CYLTabBarController;
Expand Down Expand Up @@ -290,6 +300,8 @@
9A1559E41CB6EB1F00CAB1AF /* CYLPlusButtonSubclass.m in Sources */,
9A1559DF1CB6D56500CAB1AF /* CYLSameCityViewController.m in Sources */,
9A1559DB1CB6D56500CAB1AF /* CYLHomeViewController.m in Sources */,
9A474B5D1EF1586C0020D132 /* UIControl+CYLTabBarControllerExtention.m in Sources */,
9A474B5A1EF03D1B0020D132 /* UITabBarItem+CYLTabBarControllerExtention.m in Sources */,
9AE942F91BDC937F00354519 /* CYLPlusButton.m in Sources */,
9A1559C81CB6D4D300CAB1AF /* AppDelegate.m in Sources */,
9A474C0F1EEFCCE200560ED1 /* UIView+CYLTabBarControllerExtention.m in Sources */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Example/CYLTabBarControllerConfig.m"
timestampString = "518244204.694397"
timestampString = "519049145.117056"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "207"
endingLineNumber = "207"
startingLineNumber = "208"
endingLineNumber = "208"
landmarkName = "+imageWithColor:size:"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -36,11 +36,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "CYLTabBarController/CYLTabBarController.m"
timestampString = "518268313.152042"
timestampString = "519062970.556879"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "208"
endingLineNumber = "208"
startingLineNumber = "212"
endingLineNumber = "212"
landmarkName = "-setViewControllers:"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -52,11 +52,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "CYLTabBarController/CYLTabBarController.m"
timestampString = "518268313.152042"
timestampString = "519062970.556879"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "206"
endingLineNumber = "206"
startingLineNumber = "210"
endingLineNumber = "210"
landmarkName = "-setViewControllers:"
landmarkType = "7">
<Locations>
Expand All @@ -68,11 +68,11 @@
moduleName = "CYLTabBarController"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/chenyilong/Documents/CYL/CYLTabBarController/CYLTabBarController/CYLTabBarController.m"
timestampString = "519036622.139226"
timestampString = "519137468.917978"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "206"
endingLineNumber = "206"
startingLineNumber = "210"
endingLineNumber = "210"
offsetFromSymbolStart = "1380">
</Location>
<Location
Expand All @@ -83,11 +83,11 @@
moduleName = "CYLTabBarController"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/chenyilong/Documents/CYL/CYLTabBarController/CYLTabBarController/CYLTabBarController.m"
timestampString = "519036622.140831"
timestampString = "519137468.919809"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "206"
endingLineNumber = "206"
startingLineNumber = "210"
endingLineNumber = "210"
offsetFromSymbolStart = "1395">
</Location>
</Locations>
Expand Down Expand Up @@ -132,11 +132,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "CYLTabBarController/CYLTabBarController.m"
timestampString = "518268313.152042"
timestampString = "519062970.556879"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "326"
endingLineNumber = "326"
startingLineNumber = "330"
endingLineNumber = "330"
landmarkName = "-tabBarController:shouldSelectViewController:"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -148,30 +148,14 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "CYLTabBarController/CYLTabBarController.m"
timestampString = "518268313.152042"
timestampString = "519062970.556879"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "267"
endingLineNumber = "267"
startingLineNumber = "271"
endingLineNumber = "271"
landmarkName = "-getImageFromImageInfo:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Example/AppDelegate.m"
timestampString = "519035754.744564"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "78"
endingLineNumber = "78"
landmarkName = "-tabBarController:didSelectControl:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
9 changes: 9 additions & 0 deletions CYLTabBarController/CYLTabBarController.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#import "CYLPlusButton.h"
#import "UIViewController+CYLTabBarControllerExtention.h"
#import "UIView+CYLTabBarControllerExtention.h"
#import "UITabBarItem+CYLTabBarControllerExtention.h"
#import "UIControl+CYLTabBarControllerExtention.h"

@class CYLTabBarController;
typedef void(^CYLViewDidLayoutSubViewsBlock)(CYLTabBarController *tabBarController);

FOUNDATION_EXTERN NSString *const CYLTabBarItemTitle;
FOUNDATION_EXTERN NSString *const CYLTabBarItemImage;
Expand All @@ -30,6 +35,10 @@ FOUNDATION_EXTERN CGFloat CYLTabBarItemWidth;

@interface CYLTabBarController : UITabBarController <CYLTabBarControllerDelegate>

@property (nonatomic, copy) CYLViewDidLayoutSubViewsBlock viewDidLayoutSubviewsBlock;

- (void)setViewDidLayoutSubViewsBlock:(CYLViewDidLayoutSubViewsBlock)viewDidLayoutSubviewsBlock;

/*!
* An array of the root view controllers displayed by the tab bar interface.
*/
Expand Down
6 changes: 5 additions & 1 deletion CYLTabBarController/CYLTabBarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ - (void)viewDidLoad {
[self.tabBar addObserver:self forKeyPath:@"tabImageViewDefaultOffset" options:NSKeyValueObservingOptionNew context:CYLTabImageViewDefaultOffsetContext];
self.observingTabImageViewDefaultOffset = YES;
}

}

- (void)setViewDidLayoutSubViewsBlock:(CYLViewDidLayoutSubViewsBlock)viewDidLayoutSubviewsBlock {
_viewDidLayoutSubviewsBlock = viewDidLayoutSubviewsBlock;
}

//Fix issue #93
Expand All @@ -57,6 +60,7 @@ - (void)viewDidLayoutSubviews {
[control addTarget:self action:actin forControlEvents:UIControlEventTouchUpInside];
}
}
!self.viewDidLayoutSubviewsBlock ?: self.viewDidLayoutSubviewsBlock(self);
});

}
Expand Down
30 changes: 30 additions & 0 deletions CYLTabBarController/UIControl+CYLTabBarControllerExtention.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// CYLTabBarController.m
// CYLTabBarController
//
// v1.12.0 Created by 微博@iOS程序犭袁 ( http://weibo.com/luohanchenyilong/ ) on 10/20/15.
// Copyright © 2015 https://github.com/ChenYilong . All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UIControl (CYLTabBarControllerExtention)

- (UIImageView *)cyl_imageView;
- (UIView *)cyl_tabBadgeView;
- (UIImageView *)cyl_tabImageView;
- (UILabel *)cyl_tabLabel;

/*!
* 调用该方法前已经添加了系统的角标,调用该方法后,系统的角标并未被移除,只是被隐藏,调用 `-cyl_removeTabBadgePoint` 后会重新展示。
*/
- (void)cyl_showTabBadgePoint;
- (void)cyl_removeTabBadgePoint;
- (BOOL)cyl_isShowTabBadgePoint;
- (void)cyl_setShowTabBadgePoint:(BOOL)showTabBadgePoint;

@property (nonatomic, strong, setter=cyl_setTabBadgePointView:, getter=cyl_tabBadgePointView) UIView *tabBadgePointView;

@property (nonatomic, assign, setter=cyl_setTabBadgePointViewOffset:, getter=cyl_tabBadgePointViewOffset) UIOffset tabBadgePointViewOffset;

@end
152 changes: 152 additions & 0 deletions CYLTabBarController/UIControl+CYLTabBarControllerExtention.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
//
// CYLTabBarController.m
// CYLTabBarController
//
// v1.12.0 Created by 微博@iOS程序犭袁 ( http://weibo.com/luohanchenyilong/ ) on 10/20/15.
// Copyright © 2015 https://github.com/ChenYilong . All rights reserved.
//

#import "UIControl+CYLTabBarControllerExtention.h"
#import <objc/runtime.h>
#import "UIView+CYLTabBarControllerExtention.h"

@implementation UIControl (CYLTabBarControllerExtention)

- (void)cyl_showTabBadgePoint {
[self cyl_setShowTabBadgePoint:YES];
}

- (void)cyl_removeTabBadgePoint {
[self cyl_setShowTabBadgePoint:NO];
}

- (BOOL)cyl_isShowTabBadgePoint {
return !self.tabBadgePointView.hidden;
}

- (void)cyl_setShowTabBadgePoint:(BOOL)showTabBadgePoint {
if (showTabBadgePoint && self.tabBadgePointView.superview == nil) {
[self addSubview:self.tabBadgePointView];
[self bringSubviewToFront:self.tabBadgePointView];
self.tabBadgePointView.layer.zPosition = MAXFLOAT;
// X
[self addConstraint:
[NSLayoutConstraint constraintWithItem:self.tabBadgePointView //self.cyl_imageView
attribute:NSLayoutAttributeCenterX
relatedBy:0
toItem:self.cyl_imageView
attribute:NSLayoutAttributeRight
multiplier:1
constant:self.tabBadgePointViewOffset.horizontal]];
//Y
[self addConstraint:
[NSLayoutConstraint constraintWithItem:self.tabBadgePointView //self.cyl_imageView
attribute:NSLayoutAttributeCenterY
relatedBy:0
toItem:self.cyl_imageView
attribute:NSLayoutAttributeTop
multiplier:1
constant:self.tabBadgePointViewOffset.vertical]];
}

self.tabBadgePointView.hidden = showTabBadgePoint == NO;
self.cyl_tabBadgeView.hidden = showTabBadgePoint == YES;
}

- (void)cyl_setTabBadgePointView:(UIView *)tabBadgePointView {
if (tabBadgePointView.superview) {
[tabBadgePointView removeFromSuperview];
}

tabBadgePointView.hidden = YES;
objc_setAssociatedObject(self, @selector(cyl_tabBadgePointView), tabBadgePointView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (UIView *)cyl_tabBadgePointView {
UIView *tabBadgePointView = objc_getAssociatedObject(self, @selector(cyl_tabBadgePointView));

if (tabBadgePointView == nil) {
tabBadgePointView = self.cyl_defaultTabBadgePointView;
objc_setAssociatedObject(self, @selector(cyl_tabBadgePointView), tabBadgePointView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
return tabBadgePointView;
}

- (void)cyl_setTabBadgePointViewOffset:(UIOffset)tabBadgePointViewOffset {
objc_setAssociatedObject(self, @selector(cyl_tabBadgePointViewOffset), [NSValue valueWithUIOffset:tabBadgePointViewOffset], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

//offset如果都是整数,则往右下偏移
- (UIOffset)cyl_tabBadgePointViewOffset {
id tabBadgePointViewOffsetObject = objc_getAssociatedObject(self, @selector(cyl_tabBadgePointViewOffset));
UIOffset tabBadgePointViewOffset = [tabBadgePointViewOffsetObject UIOffsetValue];
return tabBadgePointViewOffset;
}

- (UIImageView *)cyl_imageView {
for (UIView *subview in self.subviews) {
if ([subview cyl_isTabImageView]) {
return (UIImageView *)subview;
}
}
return nil;
}

- (UIView *)cyl_tabBadgeView {
for (UIView *subview in self.subviews) {
if ([subview cyl_isTabBadgeView]) {
return (UIView *)subview;
}
}
return nil;
}

- (UIImageView *)cyl_tabImageView {
for (UIImageView *subview in self.subviews) {
if ([subview cyl_isTabImageView]) {
return (UIImageView *)subview;
}
}
return nil;
}
- (UILabel *)cyl_tabLabel {
for (UILabel *subview in self.subviews) {
if ([subview cyl_isTabLabel]) {
return (UILabel *)subview;
}
}
return nil;
}

#pragma mark - private method

- (UIView *)cyl_defaultTabBadgePointView {
CGFloat const defaultTabBadgePointViewRadius = 4.5;
UIView * defaultTabBadgePointView = [[UIView alloc] init];
[defaultTabBadgePointView setTranslatesAutoresizingMaskIntoConstraints:NO];
defaultTabBadgePointView.backgroundColor = [UIColor redColor];
defaultTabBadgePointView.layer.cornerRadius = defaultTabBadgePointViewRadius;
defaultTabBadgePointView.layer.masksToBounds = YES;
defaultTabBadgePointView.hidden = YES;
// Width constraint
[defaultTabBadgePointView addConstraint:[NSLayoutConstraint constraintWithItem:defaultTabBadgePointView
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute: NSLayoutAttributeNotAnAttribute
multiplier:1
constant:defaultTabBadgePointViewRadius * 2]];

// Height constraint
[defaultTabBadgePointView addConstraint:[NSLayoutConstraint constraintWithItem:defaultTabBadgePointView
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute: NSLayoutAttributeNotAnAttribute
multiplier:1
constant:defaultTabBadgePointViewRadius * 2]];
return defaultTabBadgePointView;
}

@end

Loading

0 comments on commit a6c3be7

Please sign in to comment.