| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 118f9bb commit 5410ba0
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -112,7 +112,7 @@ screen. | |||
| 112 | 112 | ||
| 113 | 113 | --- | |
| 114 | 114 | ||
| 115 | - Could you show me how to place a UIViewController (instead of just a UIView) | ||
| 115 | + Could you show me how to place a `UIViewController` (instead of just a `UIView`) | ||
| 116 | 116 | inside SwiftUI views? | |
| 117 | 117 | ||
| 118 | 118 | --- | |
@@ -216,3 +216,45 @@ This means, for instance, that a SwiftUI `Button` does not become a `UIButton` | |||
| 216 | 216 | on iOS or a `NSButton` on macOS. It remains a SwiftUI `Button`, but it is drawn | |
| 217 | 217 | and behaves appropriately for the platform it's running on, thanks to the | |
| 218 | 218 | rendering done by SwiftUI using the native technologies. | |
| 219 | + | ||
| 220 | + --- | ||
| 221 | + | ||
| 222 | + A vanilla SwiftUI `Button` (rendered on iOS) and a vanilla `UIButton` won't look | ||
| 223 | + the same, will they (without additional styling)? | ||
| 224 | + | ||
| 225 | + --- | ||
| 226 | + | ||
| 227 | + Without additional styling, a SwiftUI `Button` and a UIKit `UIButton` will look | ||
| 228 | + different. By default, SwiftUI `Button` on iOS has a plain text look, without | ||
| 229 | + the rounded-rect border that a UIButton has in its default state. | ||
| 230 | + | ||
| 231 | + Here's an example: | ||
| 232 | + | ||
| 233 | + SwiftUI `Button`: | ||
| 234 | + | ||
| 235 | + ```swift | ||
| 236 | + Button("Hello SwiftUI") { | ||
| 237 | + print("Button tapped!") | ||
| 238 | + } | ||
| 239 | + ``` | ||
| 240 | + | ||
| 241 | + UIKit `UIButton`: | ||
| 242 | + | ||
| 243 | + ```swift | ||
| 244 | + let button = UIButton(type: .system) | ||
| 245 | + button.setTitle("Hello UIKit", for: .normal) | ||
| 246 | + button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside) | ||
| 247 | + ``` | ||
| 248 | + | ||
| 249 | + The SwiftUI `Button` will show just the text "Hello SwiftUI", whereas the UIKit | ||
| 250 | + `UIButton` will show the text "Hello UIKit" inside a rounded-rect border. | ||
| 251 | + | ||
| 252 | + This difference is part of SwiftUI's design. In SwiftUI, a `Button` is a role, | ||
| 253 | + not a specific look or behavior. The look and behavior of a SwiftUI `Button` are | ||
| 254 | + determined by the context in which the button is used, and you can easily | ||
| 255 | + customize the button's appearance using modifiers. | ||
| 256 | + | ||
| 257 | + That said, it's also worth noting that the look of UI elements can be affected | ||
| 258 | + by many factors, including iOS version, device settings, and app-specific | ||
| 259 | + settings. The details I've provided are typical, but there might be cases where | ||
| 260 | + SwiftUI `Button` and UIKit `UIButton` look similar or even identical. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments