- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//添加标签的点击手势
l = [[UILabel alloc] initWithFrame:CGRectMake(60, 90, 100, 50)];
l.userInteractionEnabled=YES;
UITapGestureRecognizer *labelTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(labelTouchUpInside:)];
l.backgroundColor = [UIColor redColor];
[l addGestureRecognizer:labelTapGestureRecognizer];
[self.view addSubview:l];
}
-(void) labelTouchUpInside:(UITapGestureRecognizer *)recognizer{
UILabel *label=(UILabel*)recognizer.view;
NSLog(@"%@被点击了",label.text);
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"设置昵称"
message:@"请输入昵称"
delegate:self cancelButtonTitle:@"取消"
otherButtonTitles:@"确定", nil];
[alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
[alertView show];
}
#pragma mark 获得输入框里的值
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSString *buttonTitle = [alertView buttonTitleAtIndex:buttonIndex];
if ([buttonTitle isEqualToString:@"确定"]){
UITextField *tf=[alertView textFieldAtIndex:0];//获得输入框
NSString * res = tf.text;//获得值
NSLog(@"%@",res);
l.text = res;
}
}