Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加了titleStrokeWidth文字描边功能 #641

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions WMPageController/WMMenuView/WMMenuItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<WMMenuItemDelegate> delegate;
@property (nonatomic, assign, readonly) BOOL selected;

Expand Down
19 changes: 19 additions & 0 deletions WMPageController/WMMenuView/WMMenuItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ - (instancetype)initWithFrame:(CGRect)frame {
self.normalSize = 15;
self.selectedSize = 18;
self.numberOfLines = 0;
self.strokeWidth = 0;

[self setupGestureRecognizer];
}
Expand Down Expand Up @@ -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];
Expand Down
1 change: 1 addition & 0 deletions WMPageController/WMMenuView/WMMenuView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions WMPageController/WMMenuView/WMMenuView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
7 changes: 7 additions & 0 deletions WMPageController/WMPageController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions WMPageController/WMPageController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down