Created
August 31, 2017 10:10
-
-
Save Darkyenus/ecc129e6ec065304ceccf9bae201ba8f to your computer and use it in GitHub Desktop.
Multi-OS-Engine Underline on NSAttributedString
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected static void makeTitleUnderlined(UIButton button, String title) { | |
final NSMutableAttributedString underlinedTitle = NSMutableAttributedString.alloc().initWithString(title); | |
NSMutableAttributedStringFix.makeUnderlined(underlinedTitle, NSMakeRange(0, underlinedTitle.length())); | |
button.setAttributedTitleForState(underlinedTitle, UIControlState.Normal); | |
} | |
/** | |
* Binding to the ObjC part of the workaround | |
*/ | |
@Runtime(ObjCRuntime.class) | |
@ObjCCategory(NSMutableAttributedString.class) | |
private static class NSMutableAttributedStringFix extends NSMutableAttributedString { | |
static { | |
NatJ.register(); | |
} | |
protected NSMutableAttributedStringFix(Pointer peer) { | |
super(peer); | |
} | |
@Selector("makeUnderlined:") | |
public static native void makeUnderlined(NSMutableAttributedString self, @ByValue NSRange range); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <UIKit/UIKit.h> | |
@implementation NSMutableAttributedString (NSMutableAttributedStringFix) | |
- (void)makeUnderlined:(NSRange)range { | |
[self addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle | NSUnderlinePatternSolid) range:range]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See https://discuss.multi-os-engine.org/t/mysterious-crash-how-to-debug-it/1149