Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何给html里的图片添加点击事件? #4

Open
kakashilw opened this issue Aug 17, 2020 · 1 comment
Open

如何给html里的图片添加点击事件? #4

kakashilw opened this issue Aug 17, 2020 · 1 comment

Comments

@kakashilw
Copy link

kakashilw commented Aug 17, 2020

你好,我看了你的示例代码,里面有把html转变成NSAttributedString的方法

NSAttributedString *attributeString = [NSAttributedString htmlString:html];
......
cell.textLabel.attributedText = attributeString;

但是,如果html里面有图片,比如

<img src=“https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574248377078&di=cf53e56d95c97225082e2063d94fb151&imgtype=0&src=http%3A%2F%2Fi1.sinaimg.cn%2Fent%2Fd%2F2008-06-04%2FU105P28T3D2048907F326DT20080604225106.jpg” />

要如何给这个图片添加点击事件呢?

@rztime
Copy link
Owner

rztime commented Aug 19, 2020

你好,我看了你的示例代码,里面有把html转变成NSAttributedString的方法

NSAttributedString *attributeString = [NSAttributedString htmlString:html];
......
cell.textLabel.attributedText = attributeString;

但是,如果html里面有图片,比如

<img src=“https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574248377078&di=cf53e56d95c97225082e2063d94fb151&imgtype=0&src=http%3A%2F%2Fi1.sinaimg.cn%2Fent%2Fd%2F2008-06-04%2FU105P28T3D2048907F326DT20080604225106.jpg” />

要如何给这个图片添加点击事件呢?

要实现点击事件,用UITextView
1.
self.textView2.rzDidTapTextView = ^BOOL(id _Nullable tapObj) { NSLog(@"%@", tapObj); return NO; };

2.两种方式
a. 给image加一个链接 <a(标签) href = "http://clickedimage" >
b.先转换为NSAttributedString, 然后找到里边的图片,然后给图片添加一个tapAction
demo: - getCache:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants