3

我使用 nsattributedstring 在 uitextview 中插入 UIimage 作为 NSTextAttachment。

现在由于 attrbutestring 的一些默认属性,我的图像上出现了长按事件。

即,当我在 UIImage 中长按时,它得到 UIActionsheet,让我选择“保存图像”或“复制”。

我没有为此编写任何代码..

我在长按 UIIMAGE 时真正想要的是我想将那个小的 UIIMAGE 打开到我的全屏中,就像我们在 whatapp 中聊天一样。当用户发送一些图像并且用户单击该图像时,它会全屏显示。

任何人请帮我定制这个 nstextattachment 的点击事件。

 NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"Somestring"];

        CGRect rect = CGRectMake(0,0,100,100);
        UIGraphicsBeginImageContext( rect.size );
        [image drawInRect:rect];
        UIImage *picture1 = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

        NSData *imageData = UIImagePNGRepresentation(picture1);
        UIImage *img=[UIImage imageWithData:imageData];

        NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
        textAttachment.image =img;
        NSAttributedString *attrStringWithImage = [NSAttributedString attributedStringWithAttachment:textAttachment];
       [attributedString replaceCharactersInRange:NSMakeRange(0,0) withAttributedString:attrStringWithImage];
    UITextView *messageContentView=[[UITextView alloc] init];
    messageContentView.attributedText=attributedString;
4

0 回答 0