I have side bar menu in my project, it is work correctly, but I want to use every side bar option menu, when I click any side bar menu, it may router to other Swift UI. How can I create Swift UI for every side option menu?
SideMenuViewModel:
enum SideMenuViewModel: Int, CaseIterable {
case profile
case lists
case bookmarks
case messages
var title: String {
switch self {
case .profile: return "Profile"
case .lists:
return "lists"
case .bookmarks:
return "bookmarks"
case .messages:
return "messages"
}}
var imageName: String {
switch self {
case .profile:
return "profile"
case .lists:
return "list.bullet"
case .bookmarks:
return "bookmark"
case .messages:
return "message"
}}}
SideMenuView:
struct SideMenuView: View {
@Binding var isShowing: Bool
var body: some View {
ZStack {
LinearGradient(gradient: Gradient(colors: [Color("red"),
Color("blue")]), startPoint: .top, endPoint: .bottom)
.ignoresSafeArea()
VStack {
SideMenuHeaderView(isShowing: $isShowing)
.frame(height: 240)
ForEach(SideMenuViewModel.allCases, id:\.self) { option in
NavigationLink(
destination: Text(option.title),
label: {
SideMenuOptionView(viewModel: option)
})}
Spacer()
}}.navigationBarHidden(true)
}}
Post
Replies
Boosts
Views
Activity
I have custom search bar and custom circle image in toolbar, when I click the circle image, I want to navigate new SwiftUI. Any idea will be appreciated.
ImageView:
VStack(alignment: .leading, spacing:0){
HStack(spacing: 0){
TextField("Search", text: $search)
.padding(.vertical,5)
.padding(.horizontal)
.background(Color.gray.opacity(0.090))
.cornerRadius(30)
.frame(width: 330, height: 32)
Image("imgage")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 32, height: 32)
.clipShape(Circle())
.overlay(Circle().stroke(Color("fig"), lineWidth: 1))
}
}
ContentView:
var body: some View {
//I have tabview here//
}
I have sidebar menu, I want to integrate with my app. In app, I have tabbar, sidebar menu not work correctly with tab bar. Any idea will be appreciated?
var body: some View {
SideMenuView()
TabView(selection: $selection){
PeopleView()
.tabItem {
selection == 0 ? Image("people-selected") : Image("people")
}
.tag(0)
AnimalView()
.tabItem {
selection == 1 ? Image("animal-selected") : Image("animal")
}
.tag(1)
PlantsView()
.tabItem {
selection == 2 ? Image("plants-selected") : Image("plants")
}
.tag(2)
}
I have a SwiftUI project, since long time I try to customize my project toolbar in SwiftUI, but SwiftUI 2.0 not support it. When new version of SwiftUI will release? Any idea?
I have a simple slide menu project in SwiftUI, and I want to add bottom navigation bar in my project, but when I click the slide menu button, I want to draw bottom navigation bar as well like in image. - https://stackoverflow.com/questions/66693507/using-slide-menu-with-bottom-navigation-bar Any idea will be appreciated.
Drawer:
struct Home: View {
// Hiding tab Bar...
init() {
UITabBar.appearance().isHidden = true
}
@StateObject var menuData = MenuViewModel()
@Namespace var animation
var body: some View {
HStack(spacing: 0){
// Drawer And Main View...
// Drawer...
Drawer(animation: animation)
// Main View...
TabView(selection: $menuData.selectedMenu){
Catalogue()
.tag("Catalogue")
Orders()
.tag("Your Orders")
Cart()
.tag("Your Cart")
Favourites()
.tag("Favourites")
}
.frame(width: UIScreen.main.bounds.width)
}
// Max Frame...
.frame(width: UIScreen.main.bounds.width)
// Moving View....
// 250/2 = 125....
.offset(x: menuData.showDrawer ? 125 : -125)
.overlay(
ZStack{
if !menuData.showDrawer{
DrawerCloseButton(animation: animation)
.padding()
}
},
alignment: .topLeading
)
// Setting As Environment Object....
// For Avoiding Re-Declarations...
.environmentObject(menuData)
}
}
I have simple app, when I run my project it work, but then throw error after running like "Thread 1: Fatal error: No ObservableObject of type msgDatas found. A View.environmentObject(_:) for msgDatas may be missing as an ancestor of this view."
struct Home: View {
@EnvironmentObject var data : msgDatas
var body : some View{
ZStack{
Color("bg").edgesIgnoringSafeArea(.top)
NavigationLink(destination: Message(), isActive: $data.show) {
Text("")
}
VStack{
topView()
}
}
}
}
It throw fatal error for data in " self.data.selectedData = i", even I try to calling @State for solve, but nothing change.
Main:
struct Main : View {
@EnvironmentObject var data : msgDatas
@State var show: Bool = false
var body : some View{
List(msgs){i in
cellView(pic: i.pic, name: i.name, msg: i.msg, time: i.time, msgs: i.msgs).onTapGesture {
self.data.selectedData = i
self.show.toggle()
}
}
}
}
cellView:
struct cellView : View {
var pic : String
var name : String
var msg : String
var time : String
var msgs : String
var body : some View{
HStack(spacing: 15){
Image(pic).resizable().frame(width: 50, height: 50).clipShape(Circle())
VStack(alignment:.leading,spacing: 5){
Text(name)
Text(msg).lineLimit(2)
}
Spacer()
VStack(spacing: 10){
Text(time)
if msgs != ""{
Text(msgs).padding(8).background(Color("bg")).foregroundColor(.white).clipShape(Circle())
}
else{
Spacer()
}
}
}.padding(9)
}
}
I have a simple SwiftUI project, when I click the any list items, I want to route different SwiftUI. Below, I used arrays, and for every SwiftUI, I want to use [0], [1],..., but it throw error, I do not know why? Any idea?
ContentView:
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
List(contacts) { contact in
NavigationLink(destination: NumberOneView(contact: contact)) {
ContactRow(contact: contact)
}
}
.navigationBarTitle("Contacts")
}
.environment(\.colorScheme, .light)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct ContactRow: View {
let contact: Settings
var body: some View {
HStack {
Image(contact.imageName)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 20, height: 20)
VStack(alignment: .leading) {
Text(contact.name)
.font(.system(size: 21, weight: .medium, design: .default))
}
}
}
}
Settings.swift:
import Foundation
import SwiftUI
struct Settings: Identifiable {
let imageName: String
let name: String
let id = UUID()
}
let contacts = [
Settings(imageName: "image1", name: "NumberOne"),
Settings(imageName: "image2", name: "NumberTwo"),
Settings(imageName: "image3", name: "NumberThree"),
Settings(imageName: "image4", name: "NumberFour"),
]
NumberOneView:
import SwiftUI
struct NumberOneView: View {
let contact: Settings
var body: some View {
Text("hey")
}
}
struct NumberOneView_Previews: PreviewProvider {
static var previews: some View {
NumberOneView(contact: contacts[0])
}
}
NumberTwoView:
import SwiftUI
struct NumberTwoView: View {
let contact: Settings
var body: some View {
Text("hey")
}
}
struct NumberTwoView_Previews: PreviewProvider {
static var previews: some View {
NumberTwoView(contact: contacts[1])
}
}
I have list item, and all item destination view routed to EndView, how can I add multiple destination view for every item, for example: when I click the first item it will open EndView, when I click the second item it will open NewView...., any idea will be appreciated.
Option:
struct InnerOptionValues: Codable {
var title: String
var image: String
var isAddSection: Bool
var isUseToggle: Bool
var headerTitle: String
}
extension Option {
static let listValues: [InnerOptionValues] = [
.init(title: "title1", image: "image1", isAddSection: true, isUseToggle: false, headerTitle: ""),
.init(title: "title2",image: "image2", isAddSection: false, isUseToggle: false, headerTitle: ""),
.init(title: "title3", image: "image3", isAddSection: false, isUseToggle: false, headerTitle: ""),
.init(title: "4", image: "image4", isAddSection: false, isUseToggle: false, headerTitle: ""),
.init(title: "5", image: "image5", isAddSection: false, isUseToggle: false, headerTitle: ""),
]
InnerView:
struct InnerView: View {
let value: InnerOptionValues
var body: some View {
return NavigationLink(destination: EndView(value: value)) {
HStack {
Image(value.image)
.resizable()
.frame(width: 16, height: 16)
.aspectRatio(contentMode: .fill)
Text(value.title)
.foregroundColor(.blue)
.font(.system(size: 18))
}
}
}
}
struct EndView: View {
let value: InnerOptionValues
var body: some View {
return NavigationLink(destination: EndView(value: value)) {
Text("Coming Soon!!!")
.font(.system(size: 25))
.foregroundColor(.blue)
} .navigationBarTitle(Text(value.title), displayMode: .inline)
}
}
I have list item menu project in SwiftUI, my project work, but I have list icons, they are not shown in list view, even I was try to use system image, there is not any change on screen, any idea?
struct MasterView: View {
let view1 = Menu(name:"Home", image:"image_home", destination:.home)
let view2 = Menu(name:"View 1", image:"image_view1", destination:.view1)
let view3 = Menu(name:"View 3", image:"image_view2", destination:.view2)
var body: some View {
let menus: [Menu] = [view1, view2, view3]
return List {
ForEach(menus) { menu in
self.destinationView(menu: menu)
}}}
func destinationView(menu: Menu) - some View {
switch menu.destination {
case .view1:
return NavigationLink(
destination: AnyView(View1(menu: menu))
)
{
Text("\(menu.name)")
}
case .view2:
return NavigationLink(
destination: AnyView(View2(menu: menu))
)
{
Text("\(menu.name)")
}
default:
return NavigationLink(
destination: AnyView(HomeView(menu: menu))
)
{
Text("\(menu.name)")
}}}}
Model.swift:
/// Main menu item for the list
struct Menu: Identifiable {
var id = UUID()
var name: String
var image: String
var destination: ViewType
}
enum ViewType {
case home
case view1
case view2
}
I have simple project in swiftUI, everythings is work, but
HStack for Rectangle() as I mention below, do not alignment the Rectangle and text at the same line, and idea will be appreciated.
struct App: View {
var body: some View {
GeometryReader{g in
ZStack {
ForEach(0..data.count) { i in
DrawShape(center: CGPoint(x:g.frame(in: .global).width/2, y: g.frame(in: .global).height/2), index: i)
}
}
}
.frame(height: 200)
.clipShape(Circle())
.shadow(radius: 10)
VStack{
ForEach(data) { i in
HStack {
Text(i.name)
.frame(width:100)
.padding()
GeometryReader { g in
HStack{
Spacer(minLength: 0)
Rectangle()
.fill(i.color)
.frame(width: self.getWidth(width: g.frame(in: .global).width, value: i.percent) ,height: 10)
Text(String(format: "\(i.percent)", "%.0f"))
.fontWeight(.bold)
.padding(.leading,10)
.frame(width:80)
Spacer()
}.frame(width: 240, height: 30)
}
}
}
.padding()
Spacer()
}
}
func getWidth(width: CGFloat, value: CGFloat) - CGFloat {
let temp = value / 100
return temp * width
}
}
I want to use NavigationLink for open the chat detail view when I click the rows items. Here example of code I mentioned. Any idea will be appreciated.
RecentRowView:
import SwiftUI
struct RecentRowView: View {
var recent: Profile
var animation: Namespace.ID
// Environment Object...
@EnvironmentObject var profileData: ProfileDetailModel
var body: some View {
HStack(spacing: 15){
// Making it as clickable Button....
Button(action: {
withAnimation{
profileData.selectedProfile = recent
profileData.showProfile.toggle()
}
}, label: {
ZStack{
// Without matched geometry effect simply showing image...
Image(recent.profile)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 60, height: 60)
.clipShape(Circle())
if !profileData.showProfile{
Image(recent.profile)
.resizable()
.aspectRatio(contentMode: .fill)
// Matched Geometry Effect...
// Giving unique ID that is from UUID from profile Model....
.matchedGeometryEffect(id: recent.id, in: animation)
.frame(width: 60, height: 60)
.clipShape(Circle())
}
}
})
// it decreased the highlight color....
.buttonStyle(PlainButtonStyle())
VStack{
NavigationLink(destination: ChatDetailView(), isActive: $profileData.show) {
HStack{
VStack(alignment: .leading, spacing: 8, content: {
Text(recent.userName)
.fontWeight(.bold)
Text(recent.lastMsg)
.font(.caption)
.foregroundColor(.gray)
})
Spacer(minLength: 10)
Text(recent.time)
.font(.caption2)
.foregroundColor(.gray)
}
Divider()
}
}
}
.padding(.horizontal)
}
}
struct RecentRowView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
ContentView:
struct ContentView: View {
// ANimation Namespace...
@Namespace var animation
// StateObject...
@StateObject var profileData = ProfileDetailModel()
var body: some View {
Home(animation: animation)
// setting Environment Object...
.environmentObject(profileData)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
NavigationView{
ContentView()
}
}
}
ChatDetailView:
import SwiftUI
struct ChatDetailView: View {
var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
}
}
struct ChatDetailView_Previews: PreviewProvider {
static var previews: some View {
ChatDetailView()
}
}
Hi every one, if you build a mobile project with SwiftUI, is it possible to use the app for sub version of IOS like iPhone 6s devices ?
I have new project and I added "pod 'AssetsPickerViewController', '~> 2.0' " to pod file and import AssetsPickerViewController to my project file, but still throw this error? Any idea?
I was use pod install for my project and it throw error like below.
"[!] The MyApp [Debug] target overrides the FRAMEWORK_SEARCH_PATHS build setting defined in Pods/Target Support Files/Pods-MyApp/Pods-MyApp.debug.xcconfig'. This can lead to problems with the CocoaPods installation - Use the $(inherited)` flag, or
- Remove the build settings from the target."
even I try to fix the xcode with $(inherited) in project target and project, it is still same. I don't know what I miss?