【问题标题】:How to highlight an email address after tapping点击后如何突出显示电子邮件地址
【发布时间】:2012-12-31 05:37:58
【问题描述】:

在我的表格视图中,我有名字、姓氏、电子邮件地址和电话号码。我有网络服务,通过它我可以从服务器获取数据并将其显示在我的设备上。我有一个问题,我从服务器获取的数据正在完美显示,但有些电子邮件地址很长,因此可以看到一半的电子邮件地址后跟点点(即 raboert.baderasam11@gma.. ..)。

有什么方法可以让我在点击电子邮件地址时看到其所有文本或标签突出显示,即完整的电子邮件地址?或任何突出显示电子邮件地址的工具提示?我希望它在单个视图中而不是多个视图中。这个任务必须完成。所以请帮助我。我对 iPhone 开发非常陌生。

   here is the code :-


 // Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath*)indexPath 
{    
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    NSArray* currentListOfItems=nil;
    Contact *aContact=nil;
    if(searching){
        currentListOfItems=searchResult;
        aContact=[searchResult objectAtIndex:indexPath.row];
    }else{
        currentListOfItems=content;
        aContact=[[[content objectAtIndex:indexPath.section] objectForKey:@"rowValues"]
          objectAtIndex:indexPath.row];
    }
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
    reuseIdentifier:CellIdentifier];
    UILabel *lbl3 = [[UILabel alloc]initWithFrame:CGRectMake(12, 0, 150, 20)];
    [lbl3 setTextColor:[UIColor blackColor]];
    [lbl3 setFont:[UIFont boldSystemFontOfSize:16.0]];
    lbl3.text =[NSString stringWithFormat:@"%@ %@", aContact.lastName,aContact.firstName];
    [cell addSubview:lbl3];
    UILabel *lbl1 = [[UILabel alloc]initWithFrame:CGRectMake(12, 20, 200, 20)];
    [lbl1 setTextColor:[UIColor blackColor]];
    [lbl1 setFont:[UIFont boldSystemFontOfSize:12.0]];
    lbl1.text = aContact.email;
    [cell addSubview:lbl1];
    UILabel *lbl2 = [[UILabel alloc]initWithFrame:CGRectMake(210, 20, 300, 20)];
    [lbl2 setTextColor:[UIColor grayColor]];
    [lbl2 setFont:[UIFont fontWithName:@"Arial" size:12.0]];
    lbl2.text = [NSString stringWithFormat:@"%@%@", @"| ",aContact.phone] ;
    [cell addSubview:lbl2];
    return cell;
}

【问题讨论】:

    标签: iphone objective-c ios uilabel xcode4.5


    【解决方案1】:

    当用户触摸它时,您可以使用电子邮件地址更改标签的宽度。要接收标签上的触摸启用userInteractionEnabled 并添加UITapGestureRecognizer。在手势识别器的方法中,将视图属性的宽度更改为手势识别器。

    编辑:

    默认情况下,标签不允许用户交互。为了接收手势,您必须像这样启用用户交互

    myLabel.userInteractionEnabled = YES;
    

    要添加UITapGestureRecognizer,请执行以下操作:

    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lableWasTapped:)];
    [myLabel addGestureRecognizer:tapGestureRecognizer];
    

    要对水龙头做出反应,请执行以下操作:

    - (void)lableWasTapped:(UITapGestureRecognizer*)sender {
        UILabel *label = (UILabel*)sender.view;
        CGSize labelSize = [label.text sizeWithFont:label.font];
        CGRect labelFrame = label.frame;
        labelFrame.size.width = labelSize.width;
        label.frame = labelFrame;
    }
    

    【讨论】:

    • 非常感谢您的回复。但我仍然想知道如何一起使用 userInteractionEnabled 和 UITapGestureRecognizer 。虽然这是我在开发领域的第三天,所以我在实施它时遇到了问题。如果您能帮我获取一些代码或一些参考示例,我将非常感谢。
    • 嘿,thanx,但我收到一个错误:“在'struct CGRect'中没有名为'width'的成员”在“labelFrame.width = labelSize.width;”行。我正在使用版本 IOS 5.2 。是因为它吗?
    • 是的,是的。将其更改为labelFrame.size.width = labelSize.width;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-10
    • 2015-04-24
    • 2017-05-17
    • 2014-12-10
    • 2012-08-26
    • 1970-01-01
    相关资源
    最近更新 更多