我正在制作一个注册警报视图,其中有一个UITextField,用户可以在其中输入注册号.一切都是他们的,但我想以编程方式从文本字段中删除复制粘贴功能,因为他们没有InterfaceBuilder版本的文本字段我不知道如何做到这一点..
这是我到目前为止的UIalertview ......
- (void)pleaseRegisterDevice {
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Please Register Device!" message:@"this gets covered" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
regTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[regTextField setBackgroundColor:[UIColor whiteColor]];
regTextField.textAlignment = UITextAlignmentCenter;
[myAlertView addSubview:regTextField];
[myAlertView show];
[myAlertView release];
}
Run Code Online (Sandbox Code Playgroud) 我想在UITextview上拦截长按,但不想同时禁用上下文菜单选项.
如果我在textview上使用手势识别器,它将禁用上下文菜单,所以我现在使用下面的方法.
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
//fire my method here
}
Run Code Online (Sandbox Code Playgroud)
但是,它只会在用户长按某些单词后显示上下文菜单时触发该方法.所以当用户长按空格时,只显示放大镜,我当时无法触发方法.
有没有人有更好的想法?谢谢!
//////解决了问题//////
感谢@danh和@Beppe,我甚至在UITextView上使用了点击手势.我想通过长按在textview上显示字体栏.
@First,我将UITextview子类化.
@interface LisgoTextView : UITextView {
BOOL pressing_;
}
@property (nonatomic) BOOL pressing;
@end
@interface LisgoTextView (private)
- (void)longPress:(UIEvent *)event;
@end
@implementation LisgoTextView
@synthesize pressing = pressing_;
//--------------------------------------------------------------//
#pragma mark -- Long Press Detection --
//--------------------------------------------------------------//
- (void)longPress:(UIEvent *)event {
if (pressing_) {
//post notification to show font edit bar
NSNotification *fontEditBarNotification = [NSNotification notificationWithName:@"fontEditBarNotification"
object:nil userInfo:nil];
[[NSNotificationCenter defaultCenter] postNotification:fontEditBarNotification];
}
}
- (void)touchesBegan:(NSSet *)touches …Run Code Online (Sandbox Code Playgroud)