System grouped background color on Mac Catalyst is incorrect for Light Mode - swift

I'm trying to recreate the same look and feel like the settings app on iOS in a Catalyst App.
I got a SplitViewController with a TableViewController set up as Grouped as Master and a TableViewController set up as Inset Grouped as Detail.
For the Table Views I've set the background color to System Grouped Background Color and for the Table View Cells I've set the background color to Secondary System Grouped Background Color.
Everything looks as expected on all devices (iOS / Mac) except for light mode on the Mac. It looks like the colors are inverted. The Table View should have the light grey background color and the Table View Cell should have a white background color but it's the other way around.
Is this default Mac behaviour or is something wrong?
I created a sample project on GitHub:
https://github.com/robertveringa89/systemgroupedbackgroundcolor

Seems to be a bug or intended behavior on macOS. I'm guessing it's a bug. But you can easily define your own colors with correct colors in a UIColor extension:
extension UIColor {
static var systemGroupedBackground2: UIColor {
UITraitCollection.current.userInterfaceStyle == .light ?
UIColor(hex: "F2F2F7FF") :
UIColor(hex: "000000FF")
}
static var secondarySystemGroupedBackground2: UIColor {
UITraitCollection.current.userInterfaceStyle == .light ?
UIColor(hex: "FFFFFFFF") :
UIColor(hex: "1C1C1EFF")
}
}

I ran into the same issue. I'm not sure if it is a bug, or a weird design decision on Apple's part. However, a fairly easy workaround is to create custom colors in an asset catalog that use the default colors on iPhone and iPad, but custom colors on macOS Catalyst.
Just create a color, like aGroupedBackgroundColor, make sure "Universal, iPad, Mac Catalyst" are all selected under Devices, and set appearance to "Any, Dark"
Then you can assign system colors to everything except for the macOS Catalyst light appearance. For example, for the table background, assign the "groupTableViewBackgroundColor" to all the light and dark appearances, except for Mac Catalyst Light appearance, assign "System Gray 6 Color".
Then, you can assign your aGroupedBackgroundColor in interface builder to your table view backgrounds, or reference it in code like so: UIColor(named: "aGroupedBackgroundColor")
Here's an image asset catalog example

Related

RollingPitTabBar background problem - Swift

I am using RollingPitTabBar pod. As you can see in the photo, there is a white background behind the tab. How can I remove this background? Let the background look white and match that view in color. So, I want the transparency of the background in RollingPitTabBar.
I also faced this situation. Add this to your RollingPitTabBar at storyboard :
Hope it helps...

How to fix blurry images on NSButton in cocoa application?

I have a couple of NSButtons which act like player controls (play, pause etc.)
When I assign image to them, that image looks blurry.
let playPauseButton: NSButton = {
let btn = NSButton(frame: .zero)
let image = NSImage(named: "pauseIcon")
btn.imageScaling = NSImageScaling.scaleNone
btn.image = image
btn.setAccessibilityLabel("Pause")
btn.isBordered = false
return btn
}()
The image can be viewed on:
https://www.dropbox.com/s/38tvh49ikc2m4x7/Play.pdf?dl=0
This image is .pdf, but I tried .png with 1x,2x and 3x, and it still looked blurry.
I also checked this question:
Images in NSButton and NSImageView Blurred
But it did not help me either.
The solution was very simple.
Open the asset catalog.
Select all your assets that are blurry.
Open the attribute inspector by pressing: command + option + 4.
Check the box that says "Preserve vector data".
Under that checkbox, look for the "Scale" and set it to "Single scale"
Please note that this only works if your designer exported icons as a PDF file. Also, it wont work if you just convert .png or .jpg to .pdf, the actual vector image must be exported to .pdf.
Here are a number of to try that have fixed blurry edges for me in the past.
Assuming you're running in Mojave and/or using layer backed views, be sure that the NSButton draws its own background color ( setDrawsBackground YES ). Otherwise what can happen with CoreAnimation CALayer is that the blending operation of the NSImage background alpha is substandard/wrong.
This shouldn't apply to an NSImage, but maybe its worth a shot: http://stackoverflow.com/questions/5722085/nsbezierpath-rounded-rectangle-has-bad-corners
[nsImage setScalesWhenResized:NO];
try different NSCompositingOperation NSCompositeCopy vs. NSCompositeSourceOver

Change colour of label in code - watchKit

How can I change the colour of a label in watchKit using code? There are articles about doing it on iOS but this works differently in watchKit. I would like to do it in Swift.
You want to use this Dylan Murphy:
label.setTextColor(UIColor.red)
You can change red to any default colour.

UITabBarItem images just appear as a grey block

I have created .png icons 20 x 20 and when I set the image property in the nib they just appear grey blocks.
Any ideas?
UPDATE: Here is one of the icons!
The standard tabbar icons in iOS are rendered solely from the alpha channel. Colors are ignored completely. Instead of colors you can use different alpha values that lead to a different shade of gray (or blue if selected)
Make the background of your icons transparent.
Download these attached images and pass them to your designer and ask him to just create images like these (when you open them in PS you'll know the difference)
This happened to me in iOS 5, I got around it by setting UIImage Outlet property in the Xib to 'Custom' and then set the label programmtically so : imageOne = [UIImage imageNames#"Dog.png"];
Try saving the file as png interlaced. In photoshop at least it gives you an option of interlaced or normal.

Is there a color picker library/code for iPhone development? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
Is there an existing "color picker" library for iPhone development that I could leverage for my app?
Yes there is an open source code for color picker you can use in your application. here is one http://www.fabiancanas.com/entry/iphone-color-picker
Here is a color-picker with the following features:
Shows a simple color pallete (simplifies the simple case), hue-grid or HSL selector.
iPhone 5 ready - color pallete expands to fill larger screen.
Hue grid - more variations of primary color. Color line in the bottom can be tapped to select color or grid can be swiped left and right.
HSL selector - for fine grain color selection, presents Hue circle and separate saturation and luminosity controls.
Alpha selector
Allows users to save their favorite colors. Favorites are stored in a file in the Documents directory.
Simple delegate model.
You can specify current color selection and title for header.
Screenshots:
check this URL.This may help you.http://maniacdev.com/2011/11/open-source-ios-color-picker-components-roundup/
I wrote a very simple one in Swift. It's probably not the best, but it looks nice and it's very simple.
https://github.com/EthanStrider/iOS-Projects/tree/master/ColorPickerExample
My full answer is here. If you don't want to use your own code rather than a third party library, you can do something like the following:
Make your own color picker
Add a UIView, a UIImageView, and a UISlider to the storyboard.
Use this image for the UIImageView:
Set the min and max values for the UISlider to 0.5 and 13.5.
Hook up the UI elements to the View Controller and use the following code to convert the slider position to colors.
class ViewController: UIViewController {
// RRGGBB hex colors in the same order as the image
let colorArray = [ 0x000000, 0xfe0000, 0xff7900, 0xffb900, 0xffde00, 0xfcff00, 0xd2ff00, 0x05c000, 0x00c0a7, 0x0600ff, 0x6700bf, 0x9500c0, 0xbf0199, 0xffffff ]
#IBOutlet weak var selectedColorView: UIView!
#IBOutlet weak var slider: UISlider!
#IBAction func sliderChanged(sender: AnyObject) {
selectedColorView.backgroundColor = uiColorFromHex(colorArray[Int(slider.value)])
}
func uiColorFromHex(rgbValue: Int) -> UIColor {
let red = CGFloat((rgbValue & 0xFF0000) >> 16) / 0xFF
let green = CGFloat((rgbValue & 0x00FF00) >> 8) / 0xFF
let blue = CGFloat(rgbValue & 0x0000FF) / 0xFF
let alpha = CGFloat(1.0)
return UIColor(red: red, green: green, blue: blue, alpha: alpha)
}
}
Or by positioning the slider on top of the image and setting the track tints to clear:
Here another article I found which is easy to understand, you can customize this as you require, by simple changes.
Further to kabram's answer above, and answering PsychoDad's question, there is now a fork of the original Neovera Color Picker which adds support for:
Landscape mode on iPhone
iPad (in a popover)
Animation when saving favorite colors
Uses UINavigationController to push views
Many color picker codes are available for iPhone development. You can use any according to your requirements. I suggest the following color picker, http://hayashi311.github.io/Color-Picker-for-iOS/
Here's another one, SHUColorPicker - https://github.com/sergdort/SHUColorPicker.
I thought I would throw my color picker into the ring. I use it in my app, You Doodle and I spent a couple weeks making it and testing it in the app. It contains a sample project to show you how to get started with it and is open sourced under the MIT license. It supports any device (iOS 6+), any resolution and portrait and landscape. Favorites, recents, color by hue, color wheel and importing textures, as well as deleting and moving favorites to the front is supported.
I've tried to combine the good pieces of all the other color pickers and ensure that the MIT license allows a no hassle integration into any project.
Github: https://github.com/jjxtra/DRColorPicker
Screenshots: