Skip to content

Commit a6f495a

Browse files
committed
Add a FAQ-Common Problems for some common questions which don't need to explain over time and time
1 parent 7f6f23f commit a6f495a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,35 @@ func application(_ application: UIApplication, didFinishLaunchingWithOptions lau
198198

199199
For more information, it's really recommended to check our demo, to learn detailed API usage. You can also have a check at the latest API documentation, for advanced usage.
200200

201+
## FAQ
202+
203+
### Common Problems
204+
205+
+ Using Image/WebImage/AnimatedImage in Button/NavigationLink
206+
207+
SwiftUI's button apply overlay to its content (except Text) by default, this is common mistake to write code like this, which cause strange behavior:
208+
209+
```swift
210+
// Wrong
211+
Button(action: {
212+
// Clicked
213+
}) {
214+
WebImage(url: url)
215+
}
216+
```
217+
218+
Instead, you must override the `.buttonStyle` to use the plain style. Or you can use the `.onTapGesture` modifier for touch handling. See [How to disable the overlay color for images inside Button and NavigationLink](https://www.hackingwithswift.com/quick-start/swiftui/how-to-disable-the-overlay-color-for-images-inside-button-and-navigationlink)
219+
220+
```swift
221+
// Correct
222+
Button(action: {
223+
// Clicked
224+
}) {
225+
AnimatedImage(url: url)
226+
}
227+
.buttonStyle(PlainButtonStyle())
228+
```
229+
201230
## Documentation
202231

203232
+ [SDWebImageSwiftUI API documentation](https://sdwebimage.github.io/SDWebImageSwiftUI/)

0 commit comments

Comments
 (0)