Skip to content

Commit fdc53fc

Browse files
committed
v1.2.4 add CYLPlusButtonWidthto let user access the plus button width
1 parent 4623435 commit fdc53fc

File tree

8 files changed

+14
-9
lines changed

8 files changed

+14
-9
lines changed

CYLTabBarController.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "CYLTabBarController"
3-
s.version = "1.2.3"
3+
s.version = "1.2.4"
44
s.summary = "Highly customizable tabBar and tabBarController for iOS"
55
s.description = "CYLTabBarController is iPad and iPhone compatible. Supports landscape and portrait orientations and can be used inside UINavigationController."
66
s.homepage = "https://github.com/ChenYilong/CYLTabBarController"

CYLTabBarController/CYLPlusButton.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
@class CYLTabBar;
3636

37-
extern UIButton<CYLPlusButtonSubclassing> *CYLExternPlusButton;
37+
FOUNDATION_EXTERN UIButton<CYLPlusButtonSubclassing> *CYLExternPlusButton;
3838

3939
@interface CYLPlusButton : UIButton
4040

CYLTabBarController/CYLPlusButton.m

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#import "CYLPlusButton.h"
1010
#import "CYLTabBarController.h"
1111

12+
CGFloat CYLPlusButtonWidth = 0.0f;
13+
1214
UIButton<CYLPlusButtonSubclassing> *CYLExternPlusButton = nil;
1315

1416
@implementation CYLPlusButton
@@ -19,7 +21,9 @@ @implementation CYLPlusButton
1921
+ (void)registerSubclass {
2022
if ([self conformsToProtocol:@protocol(CYLPlusButtonSubclassing)]) {
2123
Class<CYLPlusButtonSubclassing> class = self;
22-
CYLExternPlusButton = [class plusButton];
24+
UIButton<CYLPlusButtonSubclassing> *plusButton = [class plusButton];
25+
CYLExternPlusButton = plusButton;
26+
CYLPlusButtonWidth = plusButton.frame.size.width;
2327
}
2428
}
2529

CYLTabBarController/CYLTabBar.m

+2-3
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ - (void)layoutSubviews {
5050
}
5151
CGFloat barWidth = self.frame.size.width;
5252
CGFloat barHeight = self.frame.size.height;
53-
CGFloat widthOfPlusButton = CGRectGetWidth(self.plusButton.frame);
54-
CGFloat tabBarButtonW = (barWidth - widthOfPlusButton) / CYLTabbarItemsCount;
53+
CGFloat tabBarButtonW = (barWidth - CYLPlusButtonWidth) / CYLTabbarItemsCount;
5554
NSInteger buttonIndex = 0;
5655
CGFloat multiplerInCenterY;
5756
if ([[self.plusButton class] respondsToSelector:@selector(multiplerInCenterY)]) {
@@ -102,7 +101,7 @@ - (void)layoutSubviews {
102101
if ([childView isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
103102
CGFloat childViewX;
104103
if (buttonIndex >= plusButtonIndex) {
105-
childViewX = buttonIndex * tabBarButtonW + widthOfPlusButton;
104+
childViewX = buttonIndex * tabBarButtonW + CYLPlusButtonWidth;
106105
} else {
107106
childViewX = buttonIndex * tabBarButtonW;
108107
}

CYLTabBarController/CYLTabBarController.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
//
88

99
@import Foundation;
10+
@import UIKit;
1011

1112
static NSString * const CYLTabBarItemTitle = @"tabBarItemTitle";
1213
static NSString * const CYLTabBarItemImage = @"tabBarItemImage";
1314
static NSString * const CYLTabBarItemSelectedImage = @"tabBarItemSelectedImage";
1415

15-
extern NSUInteger CYLTabbarItemsCount;
16+
FOUNDATION_EXTERN NSUInteger CYLTabbarItemsCount;
17+
FOUNDATION_EXTERN CGFloat CYLPlusButtonWidth;
1618

1719
@import UIKit;
1820

Example/CYLTabBarControllerConfig.m

+1-2
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ + (void)customizeTabBarAppearance:(CYLTabBarController *)tabBarController {
138138
// Set the dark color to selected tab (the dimmed background)
139139
// TabBarItem选中后的背景颜色
140140
NSUInteger allItemsInTabBarCount = [CYLTabBarController allItemsInTabBarCount];
141-
[[UITabBar appearance] setSelectionIndicatorImage:[self imageFromColor:[UIColor yellowColor] forSize:CGSizeMake([UIScreen mainScreen].bounds.size.width / allItemsInTabBarCount, 49.f) withCornerRadius:0]];
142-
141+
[[UITabBar appearance] setSelectionIndicatorImage:[self imageFromColor:[UIColor yellowColor] forSize:CGSizeMake(([UIScreen mainScreen].bounds.size.width - CYLPlusButtonWidth) / (allItemsInTabBarCount - 1), 49.f) withCornerRadius:0]];
143142
// set the bar background color
144143
// 设置背景图片
145144
// UITabBar *tabBarAppearance = [UITabBar appearance];

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ pod update
273273

274274
> 即使加号按钮超出了tabbar的区域,超出部分依然能响应点击事件
275275
276+
并且你可以在项目中的任意位置读取到 `PlusButton` 的宽度,借助 `CYLTabBarController.h` 定义的 `CYLPlusButtonWidth` 这个extern。可参考 `+[CYLTabBarControllerConfig customizeTabBarAppearance:]` 里的用法。
276277

277278
### 补充说明
278279

0 commit comments

Comments
 (0)