-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Custom view instead of Image as placeholder? #746
Comments
Good idea! And I think the case 1 will be quite useful since it is very common. I'd be glad to see a PR if you could contribute your time to it! I have several consideration on this:
@teameh How do you think about it? Tell me if you are going to try it or if you have any good idea on this! And never mind if it is not quite possible for you to implement it, I could also do it late. :] |
Thanks for the quick reply. I'll definitely have a go at it. Thanks a lot for the pointers, that will really help. You'll probably need to rework the PR a bit but we'll see. I'll try to submit it somewhere in August. Cheers! |
@teameh Sure! +1 |
Hi @onevcat I finally had a chance to work on this, see master...teameh:custom-placeholder. (I basically copy and pasted your code 😝 ) But I ran into a couple of problems. While the protocol works fine for UIImageView the protocol should be different for UIButton or NSButton. Or well.. it would be better if it would be the same of course but that would make the protocol implementation look something like:
Not ideal. I was also wondering why you use I'm not sure if I have time to finish this PR, any time soon, go ahead with implementing it if you feel like it. |
@teameh Wow, great. I'd check it soon. I will take a look at how to make it generic and definitely we do not want to do The Thanks for your contribution! |
Cool! You don't need me to create a PR for this right? Here's my remote Good luck, cheers! |
Yes, I created a p-r and did some additional work here. It will be merged once everything goes fine. (I think it should be fine to just support Image View now, but I am still considering a better interface.) |
Implemented in 3.12.0. |
Wow, you move fast! Kudo's! |
func getImage(imageUrl: String,title:String?=nil){
let someTitle = UILabel()
view.addSubview(someTitle)
someTitle.text = title
someTitle.isHidden = true
someTitle.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
someTitle.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
someTitle.leadingAnchor.constraint(equalTo: self.view.leadingAnchor).isActive = true
someTitle.trailingAnchor.constraint(equalTo: self.view.trailingAnchor).isActive = true
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [self] in
let url = URL(string: imageUrl )
yourImage.kf.setImage(
with: url,
placeholder: (someTitle as? Placeholder),
options: [
.loadDiskFileSynchronously,
.cacheOriginalImage,
.transition(.fade(0.25))
],
completionHandler: { result in
// Done
switch result {
case .success(let value):
self.yourImage.image = value.image
case .failure(let error):
someTitle.isHidden = false
print("Error-image: \(error)")
}
}
)
}
} |
Check List
✔️ Read and checked all 3 items
Feature Request
Option to add a custom view instead of a Image as a placeholder. I've tried to abuse the
indicatorType
for this but I couldn't make it work.I can think of some number of use cases where this is handy, for example:
I'm not fully up to date with swift 3 yet, but I could work on a PR if you think this is a good idea.
The text was updated successfully, but these errors were encountered: