Select button is hidden in UIImagePicker bar coming form a WKWebView - swift

I have a WKWebview page in my app which selects an image to upload it so I have NO CONTROL over opening the UIImagePicker It happens natively but the "DONE" button which I can click is not shown in iPad ios 14.7.1 but it's actually clickable!!
This is how UIImagePicker shown natively
The red area is actually clickable!
I tried changing tint color globally but only the back arrow has changed the button is still hidden or something!

Use this:
extension UIImagePickerController {
open override func viewDidLoad() {
super.viewDidLoad()
self.modalPresentationStyle = UIModalPresentationStyle.custom
}
}
Try this:
extension UIImagePickerController {
open override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
self.navigationBar.topItem?.rightBarButtonItem?.tintColor = UIColor.black
self.navigationBar.topItem?.rightBarButtonItem?.isEnabled = true
}
}

Related

iOS 13 UITextField inputView with UIPickerView causing app to not be interact-able

I have the following code that worked before for making a UITableView cell tap to show a UIPickerView on screen:
fileprivate var hiddenField: UITextField = UITextField(frame: .zero)
override func viewDidLoad() {
//...
hiddenField.delegate = self
view.addSubview(hiddenField)
}
func selectYear() {
let yearPicker = UIPickerView()
yearPicker.dataSource = self
yearPicker.delegate = self
hiddenField.inputView = yearPicker
hiddenField.becomeFirstResponder()
}
However on iOS 13.1 simulator this code now makes it so that I can't tap anywhere in the app (can't scroll the picker view, or tap anywhere else), but the simulator is responsive since I can swipe up on the home indicator to close the app.
Did anything change regarding how this code might run on iOS 13 vs previously?

Window buttons (close etc.) not showing at first time

I have a vertical split view in the main view controller. I set the left custom view's background color. Then the three window buttons got invisible at first time after launch. But there ARE buttons on the title bar because I can tap the zoom button and make the window being fullscreen. Then I pressed esc to quit fullscreen mode. And the three buttons became visible. Please tell me why. I want them to be displayed from start up.
after launching
after quitting full screen mode
Some code:
in window controller
override func windowDidLoad() {
super.windowDidLoad()
window!.titlebarAppearsTransparent = true
window!.titleVisibility = .hidden
window!.isMovableByWindowBackground = true
window!.styleMask = [NSWindow.StyleMask.fullSizeContentView, NSWindow.StyleMask.titled, NSWindow.StyleMask.closable, NSWindow.StyleMask.miniaturizable, NSWindow.StyleMask.resizable]
}
extension for changing NSView background color
extension NSView {
#IBInspectable var backgroundColor: NSColor {
get {
let cgColor = self.layer?.backgroundColor
let result = NSColor(cgColor: (cgColor)!)
return (result)!
}
set {
self.wantsLayer = true
self.layer?.backgroundColor = newValue.cgColor
}
}
}
Settings of the window controller:

macOS application like Photos.app on macOS

I'm trying to create a macOS app like Photos.app. The NSWindowController has a toolbar with a segmented control. When you tap on the segmented control, it changes out the the NSViewController within the NSWindowController.
What I have so far is an NSWindowController with an NSViewController. I have subclassed NSWindowController where I have the method that gets called whenever the user taps on the segmented control.
Essentially, whatever segment is clicked, it will instantiate the view controller that is needed and set it to the NSWindowController's contentViewController property.
Is this the correct way of doing it?
Also, the NSWindowController, I am thinking, should have properties for each of the NSViewControllers it can switch to that get lazy loaded (loaded when the user taps them and they get held around to be re-used to prevent re-initializing).
Code:
import Cocoa
class MainWindowController: NSWindowController
{
var secondaryViewController:NSViewController?
override func windowDidLoad()
{
super.windowDidLoad()
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
}
#IBAction func segmentedControlDidChange(_ sender: NSSegmentedControl)
{
print("Index: \(sender.selectedSegment)")
if sender.selectedSegment == 3 {
if secondaryViewController == nil {
let viewController = storyboard?.instantiateController(withIdentifier: "SecondaryViewController") as! NSViewController
secondaryViewController = viewController
}
self.window?.contentViewController = self.secondaryViewController
}
}
}
I'm new to macOS development, however, I've been doing iOS for quite some time. If there is a better way, I'd like to know about it. Thanks!!!
to move the tab/segmented-control to the titlebar, you need:
add toolbar to window, and add the controls to the toolbar,
hide title:
class TopLevelWindowController: NSWindowController {
override func windowDidLoad() {
super.windowDidLoad()
if let window = window {
// reminder like style
// window.titlebarAppearsTransparent = true
window.titleVisibility = .hidden
// window.styleMask.insert(.fullSizeContentView)
}
}
}
now, toolbar will be merged into the top bar position.

How do I make a UIButton have the correct appearance with image and text?

I have a UIButton that has both an image and text in it. I am quite happy with its appearance except for when it is pressed.
Before it is pressed it looks like this:
After it is pressed it looks like this:
I am used to the appearance darkening the entire button when pressed, but for some reason when I have both an image and text is designates all the coloration to the image. I am quite aware that I can just make the entire button an image, but I am trying to keep this project as away from that style as possible. All of my other button are created with no images.
Is there any way to make the entire button darken as it normally would as it is currently setup?
You have to set the UIButton to Custom type (no System type) and change that properties:
self.yourButton.adjustsImageWhenHighlighted = false
If I get what you want try with that code:
override func viewDidLoad() {
super.viewDidLoad()
self.button.backgroundColor = UIColor.redColor()
}
#IBAction func buttonClicked(sender: UIButton) {
//Touch Up Inside action
sender.backgroundColor = UIColor.redColor()
}
#IBAction func buttonReleased(sender: UIButton) {
//Touch Down action
sender.backgroundColor = UIColor.grayColor()
}
Normal:
Pressed:
The simplest solution would be to match the text's highlight color:
button.setTitleColor(UIColor.gray, for: UIControlState.highlighted)

Hide add button

I am trying to have a button, so the user can hide the add banner if they want to, this works but when the add banner is not displaying I want the button to also be hidden. So I added the following code, but as soon as I did so, the button stopped working. Any ideas as to why?
thank you!
override func viewDidLoad() {
super.viewDidLoad()
if Banner.hidden == false{
hideAdd.hidden = false
} else {
hideAdd.hidden = true
}
The following is the code I used to hide the banner
#IBAction func HideAddButton(sender: AnyObject) {
Banner.hidden = true
}
The easiest way to hide and unhide objects on a MainStoryboard is to change the alpha to 0 in the attributes inspector. Then when you want it to appear you can just change the alpha in your code to 1 when you want it to appear in ViewController.swift. Or Vice Versa.