Objective-C截断尾部并在按下三个点时显示细节

时间:2016-05-02 11:32:36

标签: ios objective-c uilabel

我有一个长文本被截断为三个点,我希望长文本显示一个小弹出窗口,其中包含用户点击三个点时的全文。

这是文字的标签

Application.Echo True

here is the image

2 个答案:

答案 0 :(得分:0)

您可以在标签上使用tapgesture并点击alertview将显示的标签,然后在alertview上显示您想要显示的全文。

这就是我们使用tapgesture的例子: -

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTapped)];
tapGestureRecognizer.numberOfTapsRequired = 1;
[myLabel addGestureRecognizer:tapGestureRecognizer];
myLabel.userInteractionEnabled = YES;

答案 1 :(得分:0)

其中一种可能的解决方案是添加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