This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension HorizontalAlignment { | |
private enum UnderlineLeading: AlignmentID { | |
static func defaultValue(in d: ViewDimensions) -> CGFloat { | |
return d[.leading] | |
} | |
} | |
static let underlineLeading = HorizontalAlignment(UnderlineLeading.self) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ScrollView(.horizontal, showsIndicators: false, content: { | |
ScrollViewReader { scrollReader in | |
ForEach(0..<dataModel.count) { i in | |
Text(dataModel[i]) | |
.id(i) | |
.onTapGesture { | |
withAnimation{ | |
self.selection = i //change tab with animation | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct PageView: View { | |
@Binding var selection: Int | |
let dataModel: [String] | |
var body: some View { | |
TabView(selection:$selection) { | |
ForEach(0..<dataModel.count) { i in | |
VStack { | |
HStack { | |
Text(dataModel[i]) | |
.foregroundColor(Color.primary) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
@State private var selection = 1 //selected page | |
let dataModel = ["Forums", "Learn", "Careers", "Store", "About"] | |
var body: some View { | |
NavigationView { | |
VStack { | |
//ScrollableTabView | |
ScrollView(.horizontal, showsIndicators: false, content: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//use any way you want | |
struct ContentView: View { | |
var body: some View { | |
VStack { | |
Rectangle() | |
.frame(width: 100, height: 100, alignment: .center) | |
.cornerRadius(radius: 20.0, corners: [.topLeft]) | |
Rectangle() | |
.frame(width: 100, height: 100, alignment: .center) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//step 3 - crate a polymorphic view with same name as swiftUI's cornerRadius | |
extension View { | |
func cornerRadius(radius: CGFloat, corners: UIRectCorner) -> some View { | |
ModifiedContent(content: self, modifier: CornerRadiusStyle(radius: radius, corners: corners)) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//step 2 - embed shape in viewModifier to help use with ease | |
struct CornerRadiusStyle: ViewModifier { | |
var radius: CGFloat | |
var corners: UIRectCorner | |
func body(content: Content) -> some View { | |
content | |
.clipShape(CornerRadiusShape(radius: radius, corners: corners)) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//step 1 -- Create a shape view which can give shape | |
struct CornerRadiusShape: Shape { | |
var radius = CGFloat.infinity | |
var corners = UIRectCorner.allCorners | |
func path(in rect: CGRect) -> Path { | |
let path = UIBezierPath(roundedRect: rect, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius)) | |
return Path(path.cgPath) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
//step 1 -- Create a shape view which can give shape | |
struct CornerRadiusShape: Shape { | |
var radius = CGFloat.infinity | |
var corners = UIRectCorner.allCorners | |
func path(in rect: CGRect) -> Path { | |
let path = UIBezierPath(roundedRect: rect, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius)) | |
return Path(path.cgPath) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct Grid: Identifiable { | |
var id = UUID().uuidString | |
var gridText: String | |
} | |
class GridViewModel: ObservableObject{ | |
@Published var gridItems = [ |