我创建了 UITextView 的子类来添加自定义 UIMenuItem。问题是当我按下自定义操作来显示自定义项目时,文本没有突出显示。任何想法?
ActionsTextView.h
#import <UIKit/UIKit.h>
@protocol ActionsDelegate <NSObject>
- (void)addDreamSignalWithText:(NSString *)text range:(NSRange)range;
@end
@interface ActionsTextView : UITextView
#pragma mark - Delegate
@property IBOutlet id<ActionsDelegate>actionsDelegate;
#pragma mark - Methods
- (void)addDreamSignalAction:(id)sender;
@end
ActionsTextView.m
#import "ActionsTextView.h"
@implementation ActionsTextView
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
if (action == @selector(addDreamSignalAction:)) {
return YES;
}
return NO;
}
#pragma mark - Methods
- (void)addDreamSignalAction:(id)sender {
if ([_actionsDelegate respondsToSelector:@selector(addDreamSignalWithText:range:)]) {
[_actionsDelegate addDreamSignalWithText:[self.text substringWithRange:self.selectedRange]
range:self.selectedRange];
}
// Deselect text
self.selectedTextRange = nil;
}
@end
谢谢!!