【发布时间】:2016-05-02 11:32:36
【问题描述】:
我有一个被截断为三个点的长文本,我希望长文本在用户单击三个点时显示一个包含全文的小弹出窗口。
这是文本的标签
self.lblTitle.text = self.project.title;
【问题讨论】:
标签: ios objective-c uilabel
我有一个被截断为三个点的长文本,我希望长文本在用户单击三个点时显示一个包含全文的小弹出窗口。
这是文本的标签
self.lblTitle.text = self.project.title;
【问题讨论】:
标签: ios objective-c uilabel
您可以在标签上使用tapgesture 并在标签上点击alertview 并在alertview 上显示您想要显示的全文。
这就是我们如何使用 Tapgesture 的例子:-
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTapped)];
tapGestureRecognizer.numberOfTapsRequired = 1;
[myLabel addGestureRecognizer:tapGestureRecognizer];
myLabel.userInteractionEnabled = YES;
【讨论】:
一种可能的解决方案是添加一个 tapGesture。这段代码我刚做了,你可以试试看:
- (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
【讨论】: