WMPageController
WMPageController copied to clipboard
选中字体加粗 未选中字体不加粗 需求怎么去做
今天看了一下源码,Item是用UILabel实现的, 没有做选中字体和非选中的字体做区分。 作者大大是否可以做个性化的需求, 选中字体和非选中字体可以做个性化的设置
顶 需要这个需求
在这个方法试试 - (WMMenuItem *)menuView:(WMMenuView *)menu initialMenuItem:(WMMenuItem *)initialMenuItem atIndex:(NSInteger)index {
return initialMenuItem;
}
感觉这个方法里的
- (WMMenuItem *)menuView:(WMMenuView *)menu initialMenuItem:(WMMenuItem *)initialMenuItem atIndex:(NSInteger)index 这个 WMMenuItem 应该提供selectedFont与normalFont属性比较方便,而不是size
这个需求具体在哪个地方加,有大佬知道吗
pod 管理的,为了不修改源代码,hook了一下。同样也可以在原文件中改
// WMMenuItem.m
- (void)setSelected:(BOOL)selected withAnimation:(BOOL)animation {
//...
}
#import "WMMenuItem+Font.h"
#import <objc/runtime.h>
@implementation WMMenuItem (Font)
+ (void)load {
SEL origSel = @selector(setSelected:withAnimation:);
SEL swizSel = @selector(swiz_setSelected:withAnimation:);
// [WMMenuItem swizzleMethods:[self class] originalSelector:origSel swizzledSelector:swizSel];
Method origMethod = class_getInstanceMethod(self, origSel);
Method swizMethod = class_getInstanceMethod(self, swizSel);
BOOL didAddMethod = class_addMethod(self, origSel, method_getImplementation(swizMethod), method_getTypeEncoding(swizMethod));
if (didAddMethod) {
class_replaceMethod(self, swizSel, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
} else {
method_exchangeImplementations(origMethod, swizMethod);
}
}
- (void)swiz_setSelected:(BOOL)selected withAnimation:(BOOL)animation {
if (selected) {
self.font = [UIFont systemFontOfSize:self.selectedSize weight:UIFontWeightMedium];
} else {
self.font = [UIFont systemFontOfSize:self.selectedSize];
}
[self swiz_setSelected:selected withAnimation:animation];
}
@end