Post

Replies

Boosts

Views

Activity

Custom button not respecting the size defined in frame
Hi everyone, I created a custom ButtonStyle. struct ContentView: View { var body: some View { VStack { Button("Get Started") { print("button tapped") } .buttonStyle(PrimaryButtonStyle()) .frame(width: 320, height: 50) .border(.red, width: 1) } .padding() } } public struct PrimaryButtonStyle: ButtonStyle { @Environment(\.isEnabled) var isEnabled public func makeBody(configuration: Configuration) -> some View { configuration.label .fontWeight(.medium) .background(.green) .foregroundStyle(.white) .clipShape(RoundedRectangle(cornerRadius: 6)) .opacity(configuration.isPressed ? 0.8 : 1) .saturation(isEnabled ? 1 : 0) } } I used hat style on a button and also set a size using frame. But the background is not filling up to the size. You can see the frame is there (I added the red border to debug it) but the background is not filling it. I switched the positions of the modifiers on the button but that has no effect either. What am I missing here? Any help is appreciated. Thank uoi.
1
0
561
Dec ’23
Question about the feasibility of an app
Hello! I'm currently working on the iOS app for an armory management system. The function of this system is basically to manage the armory of a police station. All weapons in the armory are tagged with RFID tags and with the help of a scanner, the system keeps track of weapons taken in and out of the armory. The app also can be used to take inventory. This app cannot be used by the general public. It has an authentication flow and the only users will be law enforcement officers. Due to the nature of this app, it will have iconography and mentions of guns/weapons within the app. My question is, will that affect the app from getting accepted into the App Store? I've noticed there are apps like iGun Pro are available in the App Store but they're under Gaming. Can a normal app such as this be available in the App Store or will we have to go with an enterprise account and distribute the app outside of the App Store?
1
0
803
Jul ’21
Find which button is pressed in a Grid in SwiftUI
Hello, I'm trying to create sort of a menu view where buttons are paid out in a grid. Each menu button consists of an icon and a title. And I have multiple menus like this throughout the app. So I decided to create a reusable button view like this. swift struct MenuButton: View {     let title: String     let icon: Image     var action: () - Void     var body: some View {         Button(action: {             action()         }) {             VStack {                 icon                     .resizable()                     .aspectRatio(contentMode: .fit)                     .frame(minWidth: 40, idealWidth: 50, maxWidth: 60, minHeight: 40, idealHeight: 50, maxHeight: 60)                     .padding(.bottom, 3)                 Text(title)                     .foregroundColor(.black)                     .font(.system(size: 15, weight: .bold))                     .multilineTextAlignment(.center)                     .minimumScaleFactor(0.7)                     .lineLimit(2)             }             .padding(10)         }         .frame(maxWidth: .infinity, maxHeight: .infinity)         .aspectRatio(1, contentMode: .fill)         .overlay(RoundedRectangle(cornerRadius: 10).stroke(Color.blue, lineWidth: 0.6))     } } To keep the Menus organised, I opted to use an enum. swift enum Menu {     enum UserType: CaseIterable, CustomStringConvertible {         case new         case existing         var description: String {             switch self {             case .new:                 return "New User"             case .existing:                 return "Existing User"             }         }         var icon: String {             switch self {             case .new:                 return "new_user"             case .existing:                 return "existing_user"             }         }     }     enum Main: CaseIterable, CustomStringConvertible {         case create         case search         case notifications         var description: String {             switch self {             case .create:                 return "Create"             case .search:                 return "Search"             case .notifications:                 return "Notifications"             }         }         var icon: String {             switch self {             case .create:                 return "create"             case .search:                 return "search"             case .notifications:                 return "notifications"             }         }     } } And I display he menu grid like so. swift struct ContentView: View {     private let columns = [         GridItem(.flexible(), spacing: 20),         GridItem(.flexible(), spacing: 20)     ]     var body: some View {         ScrollView {             LazyVGrid(columns: columns, spacing: 20) {                 ForEach(Menu.UserType.allCases, id: \.self) { item in                     MenuButton(title: item.description, icon: Image(item.icon), action: {})                 }             }             .padding(.horizontal)             .padding([.top, .bottom], 20)         }     } } So far so good. The menu displays properly. But this is where I've hit a snag. I can't figure out a way to find which button user taps on. I could include the menu type inside the MenuButton view itself and pass it back in the button tap closure. swift struct MenuButton: View { let item: Menu.UserType var action: (_ item: Menu.UserType) - Void var body: some View { Button(action: { action(item) }) { // ... } // ... } } But this makes the MenuButton view couple of one menu type and not reusable. So I was wondering if there's another, better way to handle this. Any suggestions, ideas would be appreciated. Thanks.
8
0
3.4k
Feb ’21