【问题标题】:Objective-C truncate tail and showing details when pressing the three dots [duplicate]Objective-C在按下三个点时截断尾部并显示细节[重复]
【发布时间】:2016-05-02 11:32:36
【问题描述】:

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

这是文本的标签

self.lblTitle.text = self.project.title;

【问题讨论】:

    标签: ios objective-c uilabel


    【解决方案1】:

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

    这就是我们如何使用 Tapgesture 的例子:-

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

    【讨论】:

    • 在.xib文件或代码中?
    • 你可以通过代码或 xib 来做任何你喜欢的事情
    • 你能告诉我如何在.xib中添加它吗?
    • 在 xib 中,您使用按钮并在按钮上显示您在此处显示的文本给出按钮的标题,并在单击按钮时显示 alertview
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-02
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 2020-11-17
      • 1970-01-01
      • 2018-04-04
      • 1970-01-01
      相关资源
      最近更新 更多