autosave programmatically only works here and there - swift

despite no change to my application
programmatically trigering autosave for the window's frame and content size only works usualy once,
I tried differant combination like moving the window around and then cloisng it manualy and yet I still get the same result
I then have to make a new autosave name and then sometimes it works and sometimes it doesn't here's my code
view.window?.contentMinSize = NSSize(width: 310, height: 180) //Sets the view window minimum size.
view.window?.setContentSize(NSSize(width: 510, height: 233)) //Sets the view window normal size.
view.window?.isRestorable = true
view.window?.setFrameUsingName(NSWindow.FrameAutosaveName(rawValue: "autosaveformyapp"))
view.window?.titleVisibility = .visible
view.window?.titlebarAppearsTransparent = true
view.window?.hasShadow = true
view.window?.makeKeyAndOrderFront(nil)
view.window?.initialFirstResponder = view
update:
I also tried to place the auto save line at differant place
like before setting the window size but same result of it only working 1 time and then not working anymore

Related

Button text shrinks when the text is changed

Ones I change the text in button it's getting stink to font size of ~18 even though initial font size is 55. Button is not custom. It has System font.
button.setTitle("Some button text", for: .normal)
I tried manually change font size in code but it doesn't help
button.titleLabel?.font = UIFont.systemFont(ofSize: 55)
I also tried to change the name through configuration function, but there is no font size and it shrinks anyway.
`
button.configuration = paperButtonConfiguration()
func buttonConfiguration() -> UIButton.Configuration {
var config: UIButton.Configuration = .plain()
config.title = "Some button text"
//Should probably be something like this but it doesn't work
//config.font = UIFont.systemFont(ofSize: 55)
return config
}
`
While I was writing this question I kind of solve this, but not completely. If I change the button style from "plain" to "default" it works, but some weird animation of fading and appearance occurs.
How could I do this with "plain"?
UIButton has four type are Plain,Grain,Tinted,Filled .When you create a button in storyboard , button type automatically set with Plain that means new UIButton configurations is on. If you want to old behaviour , you must set style plain to default.
Or , If you want one of the style above . You need to set font like
button.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { incoming in
var outgoing = incoming
outgoing.font = UIFont.systemFont(ofSize: 50)
return outgoing
}

sectionHeaderTopPadding doesn't apply on Grouped and InsetGrouped UITableView

since iOS15 a strange top gap started to appear
after research i found out that
if #available(iOS 15, *) {
tableView.sectionHeaderTopPadding = 0
}
should solve the issue
however this works only for plain style table (UITableView.Style.plain), but my table is grouped and it looks like this property is taking no effect on GROUPED style (UITableView.Style.grouped)
is this a bug? how to remove the gap on grouped table?
According to the What's new in UIKit video from WWDC2021, top padding seems to have been added only to the plain style of UITableView.
Here's the part that mentions it
We have a new appearance for headers in iOS 15. For plain lists, section headers now display seamlessly in line with the content, and only display a visible background material when becoming pinned to the top as you scroll down. In addition, there's new padding inserted above each section header to visually separate the sections with this new design.
You should use this plain style in conjunction with index bars for fast scrubbing when list content is long as demonstrated in the Contacts app.
https://developer.apple.com/videos/play/wwdc2021/10059/?time=438
You can try this (this worked for me for grouped/insetGrouped)
if #available(iOS 15.0, *) {
UITableView.appearance().sectionHeaderTopPadding = 0
let tableHeaderView = UIView()
tableHeaderView.translatesAutoresizingMaskIntoConstraints = false
tableHeaderView.heightAnchor.constraint(equalToConstant: 5).isActive = true
UITableView.appearance().tableHeaderView = tableHeaderView
} else {
// Fallback on earlier versions
}

Is there a way in SwiftUI to detect if a user has Larger Text size enabled?

I've read all the articles about supporting dynamic text size, but my problem is that I have a view consisting of shapes and some text. I needed to hard code the height of this view, so when a user uses a larger text size the text overlaps the shapes. What I would like to do is detect when a larger text size is used and increase the hard coded height of the view.
There is an environment value for that:
#Environment(\.sizeCategory) var sizeCategory
With that, you can do stuff like:
if sizeCategory > ContentSizeCategory.large {
// views for large text
} else {
// views for regular/small text
}
You should also check out the #ScaledMetric property wrapper, which will auto-scale your var based on the user’s text size:
#ScaledMetric var height: CGFloat = 100
Here's a nice summary of both: https://swiftwithmajid.com/2019/10/09/dynamic-type-in-swiftui/

Correct icon size for Big Sur preference panels

When building my app for macOS Big Sur, and switching my preference panel toolbar style to .preference, the icons just don't seem to size correctly.
No matter if I use #1x/#2x PNG variants, or universal PDF vector images with a single scale, my icons always turn out larger and blurry compared to using a SF Symbol icon.
Now that my app needs to be backwards compatible with 10.13 I can't use symbol images.
Here is what my toolbar looks like
What is the correct way to get properly sized icons in a preference panel toolbar?
Do I need to include a margin in my vector assets? If so, what is the correct point size?
I got a good result with 26x26px vector PDF. The icon size was 22x22px with the margins but the icon was blurry. Enabling Preserve Vector Data option did the trick
You can set it under the Image Set settings:
Vector images don't seem to go well with NSToolbar. I created an NSImage extension for them to manually create a toolbar friendly image.
extension NSImage {
convenience init?(namedVectorToolbarImage name: String) {
guard let image = NSImage(named: name) else {
return nil
}
self.init()
let small = image.resized(to: .init(width: 24, height: 24))
let regular = image.resized(to: .init(width: 32, height: 32))
let reps = regular.representations + small.representations
isTemplate = true
reps.forEach {
addRepresentation($0)
}
}
The resize() method here is just another extension for producing a resized image. On top of that I set NSToolbar.sizeMode to small if the system is not (below) macOS 11.0.

Set bounds on a window that has an id

My app has a settings window, I want this window to be unique so that a user cannot display two settings windows at the same time. The problem is that I also want the window to be centered compared to the main window. I use this code (in the JS of the main window):
chrome.app.window.create("settings.html",
{
alwaysOnTop: true,
bounds: {
left: Math.round((window.screenX + (($(window).width() - 498) / 2))), // Perfect left position.
top: Math.round((window.screenY + (($(window).height() - 664) / 2))), // Perfect top position.
width: 498,
height: 664
},
frame : "none",
id: "settings",
resizable: false
}
);
The problem is that if an id is specified and a window with a matching id has been shown before, the remembered bounds will be used but I would prefer to set the bounds myself at every creation with the bounds option. Thus if the user moves the window and closes it the position would still be "perfect" at the next creation. Is there a solution to have this behavior?
Thanks for your help.
I'm afraid you can't override this.
You can reposition the window immediately on creation in the callback, using outerBounds.setPosition:
chrome.app.window.create(
"settings.html",
{/*...*/},
function(win) {
win.outerBounds.setPosition(
/*left, top*/
);
}
);
By the way, bounds is deprecated, you should switch to using innerBounds/outerBounds.
Alternatively, you can try to implement your own ID system. Don't use an ID, and check if the window you need is open (identifying it somehow) before creating it.