From 89c32a839e2c3814a028c988186ba8f55c637fb7 Mon Sep 17 00:00:00 2001 From: zzb <350991881@qq.com> Date: Wed, 23 Dec 2020 14:47:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86titleStrokeWidth?= =?UTF-8?q?=E6=96=87=E5=AD=97=E6=8F=8F=E8=BE=B9=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WMPageController/WMMenuView/WMMenuItem.h | 1 + WMPageController/WMMenuView/WMMenuItem.m | 19 +++++++++++++++++++ WMPageController/WMMenuView/WMMenuView.h | 1 + WMPageController/WMMenuView/WMMenuView.m | 5 +++++ WMPageController/WMPageController.h | 7 +++++++ WMPageController/WMPageController.m | 5 +++++ .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ .../WMMainTableViewController.m | 1 + 8 files changed, 47 insertions(+) create mode 100644 WMPageControllerDemo/WMPageControllerExample/WMPageControllerExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/WMPageController/WMMenuView/WMMenuItem.h b/WMPageController/WMMenuView/WMMenuItem.h index bf1da29..b45ca3f 100755 --- a/WMPageController/WMMenuView/WMMenuItem.h +++ b/WMPageController/WMMenuView/WMMenuItem.h @@ -28,6 +28,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, strong) UIColor *normalColor; ///> Normal状态的字体颜色,默认为黑色 (可动画) @property (nonatomic, strong) UIColor *selectedColor; ///> Selected状态的字体颜色,默认为红色 (可动画) @property (nonatomic, assign) CGFloat speedFactor; ///> 进度条的速度因数,默认 15,越小越快, 必须大于0 +@property(nonatomic,assign) CGFloat strokeWidth; @property (nonatomic, nullable, weak) id delegate; @property (nonatomic, assign, readonly) BOOL selected; diff --git a/WMPageController/WMMenuView/WMMenuItem.m b/WMPageController/WMMenuView/WMMenuItem.m index 9d747c3..a486e30 100755 --- a/WMPageController/WMMenuView/WMMenuItem.m +++ b/WMPageController/WMMenuView/WMMenuItem.m @@ -25,6 +25,7 @@ - (instancetype)initWithFrame:(CGRect)frame { self.normalSize = 15; self.selectedSize = 18; self.numberOfLines = 0; + self.strokeWidth = 0; [self setupGestureRecognizer]; } @@ -89,6 +90,24 @@ - (void)setRate:(CGFloat)rate { self.transform = CGAffineTransformMakeScale(trueScale, trueScale); } +- (void)drawTextInRect:(CGRect)rect + +{ + //描边 + CGContextRef c = UIGraphicsGetCurrentContext (); + + CGContextSetLineWidth (c, _strokeWidth * _rate); + + CGContextSetLineJoin (c, kCGLineJoinRound); + + self.textColor = self.textColor; + + CGContextSetTextDrawingMode (c, kCGTextFillStroke); + + [super drawTextInRect:rect]; + +} + - (void)setSelectedColor:(UIColor *)selectedColor { _selectedColor = selectedColor; [selectedColor getRed:&_selectedRed green:&_selectedGreen blue:&_selectedBlue alpha:&_selectedAlpha]; diff --git a/WMPageController/WMMenuView/WMMenuView.h b/WMPageController/WMMenuView/WMMenuView.h index 13f57ce..dcf2a33 100755 --- a/WMPageController/WMMenuView/WMMenuView.h +++ b/WMPageController/WMMenuView/WMMenuView.h @@ -87,6 +87,7 @@ typedef NS_ENUM(NSUInteger, WMMenuViewLayoutMode) { @property (nonatomic, weak) UIView *leftView; @property (nonatomic, weak) UIView *rightView; @property (nonatomic, copy) NSString *fontName; +@property(nonatomic,assign) CGFloat strokeWidth; @property (nonatomic, weak) UIScrollView *scrollView; /** 进度条的速度因数,默认为 15,越小越快, 大于 0 */ @property (nonatomic, assign) CGFloat speedFactor; diff --git a/WMPageController/WMMenuView/WMMenuView.m b/WMPageController/WMMenuView/WMMenuView.m index ac5bc3e..2edceb7 100755 --- a/WMPageController/WMMenuView/WMMenuView.m +++ b/WMPageController/WMMenuView/WMMenuView.m @@ -495,6 +495,11 @@ - (void)addItems { } else { item.font = [UIFont systemFontOfSize:item.selectedSize]; } + + if (self.strokeWidth) { + item.strokeWidth = self.strokeWidth; + } + if ([self.dataSource respondsToSelector:@selector(menuView:initialMenuItem:atIndex:)]) { item = [self.dataSource menuView:self initialMenuItem:item atIndex:i]; } diff --git a/WMPageController/WMPageController.h b/WMPageController/WMPageController.h index 0836c95..d6386c3 100755 --- a/WMPageController/WMPageController.h +++ b/WMPageController/WMPageController.h @@ -206,6 +206,13 @@ extern NSString *const WMControllerDidFullyDisplayedNotification; */ @property (nonatomic, nullable, copy) NSString *titleFontName; +/** +* 描边宽度 +* The name of title's font +*/ +@property(nonatomic,assign) CGFloat titleStrokeWidth; + + /** * 每个 MenuItem 的宽度 * The item width,when all are same,use this property diff --git a/WMPageController/WMPageController.m b/WMPageController/WMPageController.m index b72c62a..1366de3 100755 --- a/WMPageController/WMPageController.m +++ b/WMPageController/WMPageController.m @@ -464,6 +464,11 @@ - (void)wm_addMenuView { if (self.titleFontName) { menuView.fontName = self.titleFontName; } + + if (self.titleStrokeWidth) { + menuView.strokeWidth = self.titleStrokeWidth; + } + if (self.progressColor) { menuView.lineColor = self.progressColor; } diff --git a/WMPageControllerDemo/WMPageControllerExample/WMPageControllerExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/WMPageControllerDemo/WMPageControllerExample/WMPageControllerExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/WMPageControllerDemo/WMPageControllerExample/WMPageControllerExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/WMPageControllerDemo/WMPageControllerExample/WMPageControllerExample/WMMainTableViewController.m b/WMPageControllerDemo/WMPageControllerExample/WMPageControllerExample/WMMainTableViewController.m index 60dd0ec..8a7826a 100644 --- a/WMPageControllerDemo/WMPageControllerExample/WMPageControllerExample/WMMainTableViewController.m +++ b/WMPageControllerDemo/WMPageControllerExample/WMPageControllerExample/WMMainTableViewController.m @@ -86,6 +86,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath vc.title = key; vc.menuViewStyle = style; vc.automaticallyCalculatesItemWidths = YES; + vc.titleStrokeWidth = 2; if ([key isEqualToString:@"WMMenuViewStyleNaughty"]) { vc.progressViewIsNaughty = YES; vc.progressWidth = 10;