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.
Post
Replies
Boosts
Views
Activity
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?
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.
Hello,I'm trying to display MFMailComposeViewController in an app.if MFMailComposeViewController.canSendMail() {
let mailComposeViewController = MFMailComposeViewController()
mailComposeViewController.navigationBar.tintColor = .white
mailComposeViewController.mailComposeDelegate = self
mailComposeViewController.setToRecipients(["support@gmail.com"])
mailComposeViewController.setSubject("Feedback")
present(mailComposeViewController, animated: true)
} else {
print("This device is not configured to send email. Please set up an email account.")
}This is how I set the styles for the navigation bars.UINavigationBar.appearance().barTintColor = .green
UINavigationBar.appearance().tintColor = .white
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
if #available(iOS 11.0, *) {
UINavigationBar.appearance().largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
}In iOS 12, it shows up without an issue. See here.For iOS 13, I added the following code for setting the styles.if #available(iOS 13.0, *) {
let navigationBarAppearance = UINavigationBarAppearance()
navigationBarAppearance.configureWithOpaqueBackground()
navigationBarAppearance.backgroundColor = .green
navigationBarAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
navigationBarAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
UINavigationBar.appearance().standardAppearance = navigationBarAppearance
UINavigationBar.appearance().scrollEdgeAppearance = navigationBarAppearance
}But when I run on a device (iOS 13.2), the colors don't show up. See here.Is this an iOS bug? Or am I missing something in the appearance setting?Thanks!
I have an older project written in Swift 4 (Xcode 10.1). It's not possible to upgrade it to Swift 5 at this time due to having dependancies relying on older Swift versions.Is it still possible to add Sign in with Apple to this project?I opened the project in Xcode 11.3 and enabled the capability. Then I went back to Xcode 10.1 and imported `AuthenticationServices` but I cannot access any other classes of that framework.
Hello,I'm displaying a `MFMailComposeViewController` using the below code.if MFMailComposeViewController.canSendMail() {
let mailComposeViewController = MFMailComposeViewController()
mailComposeViewController.navigationBar.tintColor = .white
mailComposeViewController.mailComposeDelegate = self
mailComposeViewController.setToRecipients(["support@gmail.com"])
mailComposeViewController.setSubject("Feedback")
present(mailComposeViewController, animated: true)
} else {
print("This device is not configured to send email. Please set up an email account.")
}This worked just fine on both devices and simulators in Xcode 10.In the new Xcode 11 simulators, the compose view controller dismisses by itself as soon as it appears. See here.The following error also shows up in the Xcode console.
[Common] [FBSSystemService][0x5f27] Error handling open request for com.apple.MailCompositionService: { userInfo = { FBSOpenApplicationRequestID = 0x5f27; } underlyingError = ; } 2019-11-01 14:40:05.214158+0530 MailCompose[11289:262267] [Assert] Connection request invalidated without resuming our _serviceSessionConnection. This is an error. 2019-11-01 14:40:05.216901+0530 MailCompose[11289:262054] [General] #CompositionServices _serviceViewControllerReady: NSError Domain=_UIViewServiceInterfaceErrorDomain Code=0
This happens in all Xcode 11 versions. Is this an Xcode bug? Is there a workaround?Thanks!