( 3 ) Label文字竖排
UILabel *verticalLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 50, 100)]; verticalLabel.text = @"你\n好\n阿"; // verticalLabel.text = @"你 \n 好 \n 阿"; verticalLabel.numberOfLines = [verticalLabel.text length]; [self.view addSubview:verticalLabel];
( 2 ) 如何在敲击手势中获取到被点击的label
①
// 敲击事件[label addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTap:)]];// UILabel 默认用户交互是关闭的label.userInteractionEnabled = YES;// 添加tag值//label.tag = 4869;
②
// 点击结束调用- (void)labelTap:(UITapGestureRecognizer *)sender { /* 方法一 添加 tag值 判断 tag要少用 所以此方法不推荐 NSLog(@"%ld",sender.self.view.tag); */ // 方法 二 类型判断 if ([sender.self.view isKindOfClass:[<#你要的类#> class]]) { //转换一下 <#你要的类#> *label = (<#你要的类#> *)sender.self.view; }}
( 1 ) UILabel 添加敲击事件
- (void)loadContent { #pragma mark - label 敲击事件 [self.label addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTap)]]; // UILabel 默认用户交互是关闭的 self.label.userInteractionEnabled = YES; }// 点击结束调用- (void)labelTap { NSLog(@"点击了 label"); }