Created
August 17, 2021 12:58
-
-
Save hira22/3874525cde4969d276e69ceda6a25254 to your computer and use it in GitHub Desktop.
This file contains 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
// | |
// LineDivider.swift | |
// | |
// | |
// Created by hira22 on 2021/08/13. | |
// | |
import SwiftUI | |
struct LineDivider: View { | |
struct Line: Shape { | |
func path(in rect: CGRect) -> Path { | |
var path = Path() | |
path.addLines([ | |
CGPoint(x: .zero, y: rect.maxY / 2), | |
CGPoint(x: rect.maxX, y: rect.maxY / 2) | |
]) | |
return path | |
} | |
} | |
let text: String | |
var body: some View { | |
HStack(spacing: 16.0) { | |
LineDivider() | |
.stroke(lineWidth: 2.0) | |
Text(text) | |
.layoutPriority(1) | |
LineDivider() | |
.stroke(lineWidth: 2.0) | |
} | |
.foregroundColor(Color(.systemGray)) | |
} | |
} | |
struct LineDivider_Previews: PreviewProvider { | |
static var previews: some View { | |
LineDivider(text: "LineDivider") | |
.frame(height: 40) | |
.previewLayout(.sizeThatFits) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment