Hi,
If I generate an image from a symbol the resulting image is surrounded by some margins.
For example this code:
let image = UIImage(systemName: "suit.heart")
will generate this image:
As you can see there are some margins around the content.
There is a way to build an image cropped to the actual content, like showed in the below example?
Thank you
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hi,
I'm starting using StoreKit 2 and I have some questions regarding transactions.
To check which non-consumable in-app purchases the user has purchased, immediately after starting the app I look at Transaction.currentEntitlements.
That's working fine, but I have some questions about it.
Question 1:
What happens if the user is not connected to the internet? Will Transaction.currentEntitlements still return data?
Question 2:
What happens if the user sign out from the AppStore? Will Transaction.currentEntitlements be empty?
Question 3:
What happens if the user sign in AppStore with different credentials? Transaction.currentEntitlements will return the transaction of the new AppStore user?
Thank you
Hi,
I'm trying to define the style of an UIButton using UIButton.Configuration in a Mac Catalyst app.
I was able to configure the component as I want except one thing.
I want to change the style of the button when the window is not active.
The default filled style automatically do this.
For example below you can see a button configured with
UIButton.Configuration.filled().
If the window become inactive (for example by activating another application) the color of the button change, like so:
Now, If I configure a button with this configuration:
var configuration = UIButton.Configuration.plain()
configuration.background.strokeColor = .gray
configuration.baseForegroundColor = .red
configuration.baseBackgroundColor = .clear
the button display with this configuration when the window is active:
but also when it's not active:
I want to change the text color from red to gray when the window is not active.
Someone know how to do it?
Thank you
In a Core Data store I have a binary data attribute with “Allows External Storage” set to true. Everything work as expected, i.e. the data of this attribute is saved inside the _EXTERNAL_DATA folder. For every data stored into that attribute, a file is created inside _EXTERNAL_DATA with a UUID as file name and without extension. That's expected.
For some reason the _EXTERNAL_DATA folder of a particular user was full of files with an “.interim” extension.
Somebody know what are this files? In which cases files are saved with the ".interim" extension? Do we need to do anything with these files? Can they be deleted?
Thank you
When using storyboards, string catalogs automatically grab translation comments from the "Localizer Hint" attribute of the objects in the storyboard.
The problem is that we can only specify a single comment per object. What if we need to specify a specific comment for some of the attributes of the object? For example, I often need to provide a specific comment to each segment title of segmented control objects. Currently, I'm doing that by setting the managed property of each string to "Manual" and setting the comment directly from the string catalog.
There is a better way to handle these cases?
If an in-app purchase is made when my app is not running, the next time the app launches Transaction.updates will emits a transaction for the purchase. That's great.
But if an in-app purchase is refunded when my app is not running, the next time the app launches Transaction.updates will NOT emits a transaction for the refund. Is that the expected behaviour?
If yes, in order to check for refunds at app launch, are we supposed to cycle trough Transaction.all and search for them?
Thank you
I'm using the following code to get the height of the keyboard:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(
self,
selector: #selector(keyboardHeight),
name: UIResponder.keyboardDidChangeFrameNotification,
object: nil
)
}
@objc private func keyboardHeight(notification: Notification) {
guard let keyboardRect = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else { return }
print("==> keyboardFrameEndUserInfoKey height: \(keyboardRect.size.height)")
}
}
This code on iPad work correctly when the keyboard is normal but it does not work when the keyboard is floating.
After the user tap on a text field, the keyboard appear and the keyboardDidChangeFrameNotification notification is called.
If the keyboard is floating then the first time we get a wrong height of 362. If the user then manually move somewhere the floating keyboard the notification is called again and the correct value of 308 is returned.
It is a bug or I miss something? I need to be able to get the correct height the first time the keyboard appear.
This is happening on iOS 13 and iOS 14.
Any idea?
I'm developing an iOS 14 Catalyst app and I'm trying to setup the window toolbar.
I created a NSToolbar and assigned to the scene window titlebar property.
var toolbarDelegate = ToolbarDelegate()
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
#if targetEnvironment(macCatalyst)
guard let windowScene = scene as? UIWindowScene else { return }
let toolbar = NSToolbar(identifier: "main")
toolbar.delegate = toolbarDelegate
toolbar.displayMode = .iconOnly
if let titlebar = windowScene.titlebar {
titlebar.toolbar = toolbar
titlebar.toolbarStyle = .unified
titlebar.titleVisibility = .hidden
}
#endif
}
I then assigned some items to the toolbar via the toolbarDefaultItemIdentifiers delegate method.
func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
let identifiers: [NSToolbarItem.Identifier] = [
.toggleSidebar,
.print,
.flexibleSpace,
.print
]
return identifiers
}
This work as expected.
Now, let's say that I want to align some items with the edges of the supplementary column.
I found that there is an NSToolbarItem named supplementarySidebarTrackingSeparatorItemIdentifier.
This item appears to allow us to align items with the supplementary column. If I do this:
func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
let identifiers: [NSToolbarItem.Identifier] = [
.toggleSidebar,
.flexibleSpace,
.print,
.supplementarySidebarTrackingSeparatorItemIdentifier,
.print,
.flexibleSpace,
.print
]
return identifiers
}
I got the following result which is exactly what I want to achieve (the items are aligned with the supplementary column):
But there are some issues.
As you can see from the above image for some reason the background color of the toolbar on top of the supplementary column become white. But it's worse. If I resize the window the background instantly become gray:
If I then scroll the content of the supplementary column the toolbar become white again.
Another issue is that If I collapse the primary column the toolbar on top of the supplementary column loose the right separator line. Why?
I tried to search some info online but if I try to search for supplementarySidebarTrackingSeparatorItemIdentifier I got only 5 results! One of these is Apple's official documentation page, which does not contain any info about the behaviour of this item:
Apple documentation about supplementarySidebarTrackingSeparatorItemIdentifier
At this point I wonder if this item is ready to be used in real apps.
Someone has experience using the supplementarySidebarTrackingSeparatorItemIdentifier item?
There is a way to align toolbar items with the supplementary column without having the above described issues? (different toolbar background color, missing toolbar separator line)
Thank you
I need to set the value of a variable according to a preprocessor rule, like in the example below.
var doSomething = false
#if targetEnvironment(macCatalyst)
doSomething = true
#endif
if doSomething {
print("Execute!")
}
If I build the code for an iOS simulator, Xcode will generate a "Will never be executed" alert at the print("Execute!") line.
This make sense because preprocessor rules are evaluated before compilation and therefore the code above, when the target is an iOS simulator, corresponds to:
var doSomething = false
if doSomething {
print("Execute!")
}
I just want to know if there is any advices for handling cases like that.
Ideally, I would like to avoid using the preprocessor condition for every statement, like so:
#if targetEnvironment(macCatalyst)
print("Execute!")
#endif
but rely on a variable like the original example.
I would also prefer to avoid completely disabling in Xcode the display of "Will never be executed" warnings for all source codes.
Is there a way to set the "doSomething" variable so that Xcode doesn't display the warning in a case like that?
Thank you
Hi,
In a Mac Catalyst app, I need to allow the user insert a passcode using a UITextField.
The field is used to insert a one time passcode and I want to keep the content hidden. For this reason I set the isSecureTextEntry property to true.
passcodeTextField.isSecureTextEntry = true
By doing this, a button to allow the user to pick a password from the keychain is displayed:
This option in my case should not appear because the password is a one time password that change every time. For that reason I set the textContentType to oneTimeCode.
passcodeTextField.textContentType = .oneTimeCode
This actually removes the password button, but introduce something weird. If the user type something and then delete everything, a big empty box appear under the field:
I have no idea what this box is and why it appears.
Does anyone know why it appears and how I can remove it?
Thank you
Hi,
I'm looking for a way to get the list of pending purchases, i.e. the purchases made when the "Ask to buy" feature is enabled and which have yet to be approved.
I need this in order to update the UI of my store and disable the possibility to buy products when they are pending for approval.
I tried to look into Transaction.all but pending transactions seems to be missing.
How can we get the list of pending purchases?
Thank you
Hi,
I need to generate the image of a map at a specific resolution.
I tried to use the following code:
let options = MKMapSnapshotter.Options()
options.size = CGSize(width: 300, height: 200)
options.scale = 1.0
options.mapRect = mapRect
let mapSnapshotter = MKMapSnapshotter(options: options)
if let snapshot = try? await mapSnapshotter.start() {
let image = snapshot.image
}
Since I specified the options.scale to be 1 I expect the image resolution to be exactly 300x200 pixel (and with a scale of 1).
Unfortunately the resulting image has a scale factor of 3 (on an iPhone) and the actual resolution is 900x600 pixel.
I also tried, instead of using the scale option, to set the traitCollection option, like this:
options.traitCollection = UITraitCollection(displayScale: 1.0)
but I still get a 3x scale image with a resolution of 900x600.
Why is the scale option ignored? I miss something?
Thank you
Hi,
The following code allow to build an image from an UILabel:
let label = UILabel()
label.text = "test content"
label.backgroundColor = .white
label.layer.cornerRadius = 10
label.layer.masksToBounds = true
label.sizeToFit()
let format = UIGraphicsImageRendererFormat()
format.scale = 5
let renderer = UIGraphicsImageRenderer(bounds: label.bounds, format:format)
let image: UIImage? = renderer.image { rendererContext in
label.layer.render(in: rendererContext.cgContext)
}
This works perfectly on iOS but on Mac Catalyst the label text is very blurry as you can see in the image below.
Both images are created with the same exact code and have the exact same resolution of 460x103.
On top the iOS version and on bottom the Mac Catalyst version.
Note that not all of the image is blurry, but only the text. In the code I set a corner radius of 10 and you can see that the corner is rendered with an high resolution, like the iOS version. It's just the text that for some reason is blurry. It's like if the label text is rendered with a scale of 1 and then scaled up.
Someone know why? There is something I can do to improve the rendering of the text?
Thank you
Hi,
I have a controller with a UITableView.
If the user, on an iPad with a keyboard or on the Mac, press the tab key, the first cell is focused showing a border.
The user can then move the focus using the keyboard arrows.
That's ok.
The problem is that the cell is focused also when the cell is selected manually, i.e. by tapping on it.
It is possibile to keep the cell focus feature when the user use the tab key, but stop focusing the cell when it's activated directly by tapping on it?
Thank you
Hi,
I want to set the glyphImage property for an annotation view (MKMarkerAnnotationView) of a cluster annotation (MKClusterAnnotation).
Using the below code, inside the marker I get, instead of the glyphImage, the standard cluster number.
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if let cluster = annotation as? MKClusterAnnotation {
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "GroupMapClusterAnnotation")
if annotationView == nil {
annotationView = MKMarkerAnnotationView(annotation: cluster, reuseIdentifier: "GroupMapClusterAnnotation")
}
(annotationView as? MKMarkerAnnotationView)?.glyphImage = UIImage(systemName: "star.fill")
return annotationView
}
}
I think that the problem is that if you keep the glyphText property empty, MapKit automatically set it with the number of the cluster member annotations.
The documentation for glyphImage says:
Use this property or the glyphText property to specify the marker balloon content. If you specify both an image and text, MapKit displays the text.
So, MapKit is setting glyphText with a value an therefore the glyphImage property is ignored.
How can we use the glyphImage property for a cluster annotation?
Thank you