mirror of
https://github.com/ivanvorobei/SwiftUI.git
synced 2026-04-20 15:51:37 +02:00
Add Area to Card
This commit is contained in:
79
Files/AreaToCard.swift
Normal file
79
Files/AreaToCard.swift
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
// The MIT License (MIT)
|
||||||
|
// Copyright © 2019 Ivan Vorobei (hello@ivanvorobei.by)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct ContentView : View {
|
||||||
|
@State var show = false
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack() {
|
||||||
|
Text("Card in SwiftUI")
|
||||||
|
.color(.white)
|
||||||
|
.fontWeight(.bold)
|
||||||
|
.font(.largeTitle)
|
||||||
|
.padding(.top, show ? 30 : 20)
|
||||||
|
.padding(.bottom, show ? 20 : 0)
|
||||||
|
|
||||||
|
Text("Animatable cards with Spring, custom frame and some paddings. Also use SFSymbol for icon in the bottom button. Tap to button fo see fill style of this icon.")
|
||||||
|
.color(Color.white)
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
.animation(.spring())
|
||||||
|
.cornerRadius(0)
|
||||||
|
.lineLimit(0)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Button(action: {
|
||||||
|
self.show.toggle()
|
||||||
|
}) {
|
||||||
|
HStack {
|
||||||
|
Image(systemName: show ? "slash.circle.fill" : "slash.circle")
|
||||||
|
.foregroundColor(Color(hue: 0.498, saturation: 0.609, brightness: 1.0))
|
||||||
|
.font(Font.title.weight(.semibold))
|
||||||
|
.imageScale(.small)
|
||||||
|
Text(show ? "to Card" : "to Area")
|
||||||
|
.color(Color(hue: 0.498, saturation: 0.609, brightness: 1.0))
|
||||||
|
.fontWeight(.bold)
|
||||||
|
.font(.title)
|
||||||
|
.cornerRadius(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(.bottom, show ? 20 : 15)
|
||||||
|
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
.padding(.top, 15)
|
||||||
|
.frame(width: show ? 350 : 290, height: show ? 420 : 260)
|
||||||
|
.background(Color.blue)
|
||||||
|
.cornerRadius(30)
|
||||||
|
.animation(.spring())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
struct ContentView_Previews : PreviewProvider {
|
||||||
|
static var previews: some View {
|
||||||
|
ContentView()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
33
README.md
33
README.md
@@ -15,6 +15,7 @@ If you like the project, do not forget to `put star ★`
|
|||||||
## Navigate
|
## Navigate
|
||||||
|
|
||||||
- [Animatable Cards](#animatable-cards)
|
- [Animatable Cards](#animatable-cards)
|
||||||
|
- [Area to Card](#area-to-card)
|
||||||
- [Transition And Blur](#transition-and-blur)
|
- [Transition And Blur](#transition-and-blur)
|
||||||
- [2048 Game](#2048-game)
|
- [2048 Game](#2048-game)
|
||||||
- [SFSymbols](#sfsymbols)
|
- [SFSymbols](#sfsymbols)
|
||||||
@@ -53,7 +54,7 @@ Also include:
|
|||||||
|
|
||||||
## Animatable Cards
|
## Animatable Cards
|
||||||
|
|
||||||
<img align="left" src="https://hsto.org/webt/xh/3t/eq/xh3teq68fx1bujdlsgpon4jtijo.gif" width="280">
|
<img align="left" src="Resources/Preview/animatable-cards.gif" width="280">
|
||||||
|
|
||||||
### Gester
|
### Gester
|
||||||
|
|
||||||
@@ -91,6 +92,36 @@ In preview I am use `Spring` animation for all cards:
|
|||||||
|
|
||||||
```swift
|
```swift
|
||||||
.animation(.spring())
|
.animation(.spring())
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Area to Card
|
||||||
|
|
||||||
|
<img align="left" src="Resources/Preview/area-to-card.gif" width="280">
|
||||||
|
|
||||||
|
### Frame
|
||||||
|
|
||||||
|
Size of area attach to state of property `show`:
|
||||||
|
|
||||||
|
```
|
||||||
|
.frame(width: show ? 350 : 290, height: show ? 420 : 260)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Button
|
||||||
|
|
||||||
|
For change state using `@State` as property:
|
||||||
|
|
||||||
|
```
|
||||||
|
@State var show = false
|
||||||
|
```
|
||||||
|
|
||||||
|
### SFSymbols
|
||||||
|
|
||||||
|
For button using `SFSymbols` pack with ready-use icons. Also support customisable weight:
|
||||||
|
|
||||||
|
```
|
||||||
|
Image(systemName: show ? "slash.circle.fill" : "slash.circle")
|
||||||
|
.font(Font.title.weight(.semibold))
|
||||||
```
|
```
|
||||||
|
|
||||||
## Transition And Blur
|
## Transition And Blur
|
||||||
|
|||||||
BIN
Resources/Previews/animatable-cards.gif
Normal file
BIN
Resources/Previews/animatable-cards.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 457 KiB |
BIN
Resources/Previews/area-card.gif
Normal file
BIN
Resources/Previews/area-card.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 851 KiB |
Reference in New Issue
Block a user