iOS-在UILabel中设置值,值返回UILabel

来源:互联网 发布:yy mac进入房间失败 编辑:程序博客网 时间:2024/06/14 10:31

这里写图片描述
这里写图片描述
这里写图片描述

- (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;    }}
原创粉丝点击