WMPageController icon indicating copy to clipboard operation
WMPageController copied to clipboard

选中字体加粗 未选中字体不加粗 需求怎么去做

Open iYeso opened this issue 6 years ago • 5 comments

今天看了一下源码,Item是用UILabel实现的, 没有做选中字体和非选中的字体做区分。 作者大大是否可以做个性化的需求, 选中字体和非选中字体可以做个性化的设置

iYeso avatar Aug 14 '18 03:08 iYeso

顶 需要这个需求

CoderDoraemon avatar Aug 23 '18 07:08 CoderDoraemon

在这个方法试试 - (WMMenuItem *)menuView:(WMMenuView *)menu initialMenuItem:(WMMenuItem *)initialMenuItem atIndex:(NSInteger)index {

return initialMenuItem;

}

1277393484 avatar Aug 23 '18 07:08 1277393484

感觉这个方法里的

  • (WMMenuItem *)menuView:(WMMenuView *)menu initialMenuItem:(WMMenuItem *)initialMenuItem atIndex:(NSInteger)index 这个 WMMenuItem 应该提供selectedFont与normalFont属性比较方便,而不是size

sunzhongliangde avatar Oct 15 '18 01:10 sunzhongliangde

这个需求具体在哪个地方加,有大佬知道吗

LiangZhengYi avatar Nov 13 '18 08:11 LiangZhengYi

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

xiusl avatar Dec 07 '18 09:12 xiusl