Closed productdevbook closed 4 years ago
Emm. I can not get the point of your question. Could you please describe the issue clearly ? I'm not a native English speaker as well, but if you can, a image or picture to reproduce what you expected and what actual happended step by step, it's a better way to report the issue.
Can I have a guess for what you means ?
- The
SDWebImageActivityIndicator
does not get the size limit by 20x20 point
This is the designed behavior, by us, and by UIKit team. This indicator is the system UI component, see: UIActivityIndicatorView. It has only fixed size with medium
or large
. Any frame set does not take effect on them.
If you really want to scale down its size, you need to apply an affine transform. You can modifiy the native UIView of that indicator.
let indicator = SDWebImageActivityIndicator.medium
indicator.indicatorView.transform = .init(scaleX: 0.5, y: 0;5) // scale 50%
- When using indicator, the indicator animating speed is faster when loading image size is large ?
I can not reproduce this problem. The indicator size is fixed, and the animating speed is controlled by system, no customization.
If you really find this things strange, you can try to switch to WebImage
as well. Which allows SwiftUI style indicator (View), you can create your own, or using the same activityIndicator
(which bridge the UIKit).
The WebImage
can show SVG/PDF as bitmap image as well (but the resizing will cause blur). Check our demo's AppDelegate.swift
about the setup code.
See: https://stackoverflow.com/questions/2638120/can-i-change-the-size-of-uiactivityindicator
And I'm a little curious about what you want to do for that indicator. If you really want to customize, write your own indicator (the Indicator
is a protocol) from the scratch is a better idea. These indicator provided by our framework, is used for most common use case which follows the Apple Human Interface Guideline
Pictures are loading slowly. 20x20
@mkalayci35 Could you tell me what's the loading speed you talk about ?
diskCacheReadingOptions
. See the wikiOr, could you please, provide a demo? Tell me how to reproduce. This is the fast way to answer your issue.
class CountryAPIList: ObservableObject {
@Published var countryData = [CountryListEntry]()
init() {
let session = URLSession(configuration: .default)
session.dataTask(with: URL(string: "https://restcountries.eu/rest/v2/all")!) { (data, _, _) in
do {
let fetch = try JSONDecoder().decode([CountryListEntry].self, from: data!)
DispatchQueue.main.sync {
self.countryData = fetch
// print(fetch)
}
} catch {
print(error.localizedDescription)
}
}.resume()
}
}
struct CountryListEntry: Codable {
var name: String
var flag: String
}
I test our framework demo again. Even the SVG frame size set to (20, 20), nothing strange happend. So please, provide a demo to help for your issue.
var body: some View {
List(self.data.countryData ,id: \.name) { i in
Button(action: {
self.currentlySelectedId = i.name
}) {
HStack {
AnimatedImage(url: URL(string:i.flag)) // Progressive Load
.resizable() // Actually this is not needed unlike SwiftUI.Image
.placeholder(UIImage(systemName: "photo")) // Placeholder Image
// Activity Indicator
.transition(.fade) // Fade Transition
.scaledToFit() // Attention to call it on AnimatedImage, but not `some View` after View Modifier
.frame(width: 20, height: 20, alignment: .center)
Text(i.name)
Spacer()
Image(systemName: i.name == self.currentlySelectedId ? "checkmark.circle.fill" : "").foregroundColor(Color("jungleGreen"))
}
}
}
} ```
@mkalayci35 I try you code.
I don't know what's going on, that you write a Button
to wrap the HStack. But that cause strange issues. Maybe It's SwiftUI's bug or something.
Instead, remove the button that works for me.
Or, you can try to use the .buttonStyle(PlainButtonStyle())
.
Seems you're writting same strange code like the user #57
I don't know why all of new SwiftUI users (Don't have any UIKit knowledge ?) like to use Button
for navigation with a Image
view. But it's a wrong code style. You should use . onTapGesture
and navigate manually.
I update one FAQ about this common mistake. Seems that SwiftUI is new and not anyone know what Button do for its style.
thank you change WebImage(url: URL(string: i.flag), options: [],context: [.svgPrefersBitmap: true]) speed image.
.indicator(SDWebImageActivityIndicator.medium) It doesn't look 20x20 and the pictures come late. When photos are big, they come fast.