Objective-C 截尾并在按下三个点时显示详细信息
Objective-C truncate tail and showing details when pressing the three dots
我有一个被截断为三个点的长文本,我希望该长文本在用户单击三个点时显示一个包含完整文本的小弹出窗口。
这是文本的标签
self.lblTitle.text = self.project.title;
您可以通过在标签上使用 tapgesture
来执行此操作,然后在点击标签时将显示 alertview
并且在 alertview
上您可以显示您想要的全文显示。
这就是我们如何使用 taggesture 的例子 :-
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTapped)];
tapGestureRecognizer.numberOfTapsRequired = 1;
[myLabel addGestureRecognizer:tapGestureRecognizer];
myLabel.userInteractionEnabled = YES;
一种可能的解决方案是添加点击手势。我刚刚做了这个代码,你可以尝试使用它:
- (void)tapGestureToLabel {
self.lblTitle.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(callAlert)];
tapGesture.numberOfTapsRequired = 1;
[tapGesture setDelegate:self];
[self.lblTitle addGestureRecognizer:tapGesture];
}
- (void)callAlert {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:self.lblTitle.text delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[alert show];
}
您可以在
之后立即调用[self tapGestureToLabel];
self.lblTitle.text = self.project.title;
ps:不要忘记将 UIGestureRecognizerDelegate 添加到您的 @interface
我有一个被截断为三个点的长文本,我希望该长文本在用户单击三个点时显示一个包含完整文本的小弹出窗口。
这是文本的标签
self.lblTitle.text = self.project.title;
您可以通过在标签上使用 tapgesture
来执行此操作,然后在点击标签时将显示 alertview
并且在 alertview
上您可以显示您想要的全文显示。
这就是我们如何使用 taggesture 的例子 :-
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTapped)];
tapGestureRecognizer.numberOfTapsRequired = 1;
[myLabel addGestureRecognizer:tapGestureRecognizer];
myLabel.userInteractionEnabled = YES;
一种可能的解决方案是添加点击手势。我刚刚做了这个代码,你可以尝试使用它:
- (void)tapGestureToLabel {
self.lblTitle.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(callAlert)];
tapGesture.numberOfTapsRequired = 1;
[tapGesture setDelegate:self];
[self.lblTitle addGestureRecognizer:tapGesture];
}
- (void)callAlert {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:self.lblTitle.text delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[alert show];
}
您可以在
之后立即调用[self tapGestureToLabel];self.lblTitle.text = self.project.title;
ps:不要忘记将 UIGestureRecognizerDelegate 添加到您的 @interface