iOS 11 System gray color - ios

I have a UIView directly below my default Navigation Bar and I am trying to make it appear that the region is one. To do this I am trying to match the color of my custom view to the color of the navigation bar. However, it doesn't seem to be any of the UIColors such as gray or lightGray. I would assume that if it is a custom color then I would be able to pull the color from the navigation bar, but I cannot seem to find the value.

you can use digital color picker app available in mac os,
Then whichever component's color you want just hover mouse pointer there and you will get the RGB Values in digital color meter and that RGB values you can use in setting the background of your view,
in this way,
UIColor.init(red: 49.0/255.0, green: 49.0/255.0, blue: 49.0/255.0, alpha: 1.0)

Related

Swift CHARTS library how to change the legend colour to reflect Bar chart colour

I am using CHARTS library in swift. https://github.com/danielgindi/Charts and tutorial from the link https://www.appcoda.com/ios-charts-api-tutorial/ on how to customise to suit your needs.
I am trying to change the Bar chart colour using the commands below as listed in the tutorial. While the bar chart colour changes correctly but the 'legend' colour listed below the bar chart is not updated. Can some suggest how to change the legend colour to reflect the bar chart.
2 different commands suggested in the tutorial, first one to change all the bars to one single colour and second to change to multiple colours. Both works fine for changing bar chart colour but NOT the legend.
chartDataSet.colors = [UIColor(red: 230/255, green: 126/255, blue: 34/255, alpha: 1)]
chartDataSet.colors = ChartColorTemplates.colorful()
The documentation says you should refer to the android documentation.
https://github.com/PhilJay/MPAndroidChart/wiki/Legend
That one says:
you can retreive the Legend object from the chart using the
getLegend() method
Then you will have access to methods that modify the way legends look.
Styling / modifying the legend
setTextColor(int color): Sets the color of the legend labels.
setTextSize(float size): Sets the text-size of the legend labels in
dp. setTypeface(Typeface tf): Sets a custom Typeface for the legend
labels.
For swift 5 + general color change
BarChartView.legend.textColor = UIColor.white
if you want to give some special format , you can refer to
Formatting Custom Legend Entries in Chart's PieChartView?

IOS figure out shade of in grey keyboard buttons

IOS default keyboard has the following buttons:
I am trying to make my own custom keyboard and I need to figure out the shade of grey/style (if they use something special to achieve that grey look) of these buttons.
I thought the RGB value was: (170,170,170)
but the UIColor UIColor.init(red: 2/3, green: 2/3, blue: 2/3, alpha: 1)
lends me a darker color that looks like this:
Am I possibly missing a transparency value and if so how can I figure it out?
You can use a color picker to figure it out.
It's (173, 180, 190).

What is difference between White Color set from storyboard and UIColor.whiteColor()?

For a UIButton, I have set its background color as White Color in storyboard. I want to toggle the properties of the button depending on the current backgroundColor of my button.
func toggleButton(button: UIButton) {
if button.backgroundColor == UIColor.whiteColor() {
button.backgroundColor = UIColor.myDesiredColor()
button.tintColor = UIColor.whiteColor()
}else {
button.backgroundColor = UIColor.whiteColor()
button.tintColor = UIColor.myDesiredColor()
}
}
The check for button.backgroundColor == UIColor.whiteColor() never returns true and after debugging, I found out that value of White Color set from Storyboard is different from value of UIColor.whiteColor().
Debugging result:
Storyboard White Color - UIDeviceRGBColorSpace 1 1 1 1
UIColor.whiteColor() - UIDeviceWhiteColorSpace 1 1
I have found out workaround for my code to work as expected.
My real confusion are:
What is difference between these two values?
Why does Xcode have two different value of same color in storyboard and code?
How do these two different white colors differ from each other?
The variations in your results differ not so much because of the color used (after all they are both white), but rather in the resulting colorspace that is used: (RGB and the other is Device)
Device Color
Device colors are meant to be true representations of colors as perceived by the human eye. A device-independent color space starts with a white reference point, a black reference point, and gamma values for a particular device. iOS Quartz takes that information to convert colors of a source color space into the color space of the output device. Device color is also the standard defined by the International Color Consortium.
ICC profiles define the gamut of colors supported by a device along
with other device characteristics so that this information can be used
to accurately transform the color space of one device to the color
space of another.
RGB
RGB is a three-dimensional color space are made up of varying values of red, green, and blue intensities that make up a given color. It's the most commonly used color space in computer graphics, because it's directly supported by most every color display that's around today. RGB color spaces are device dependent and additive.
Signals are transmitted to the elements on the face of the monitor,
causing them to glow at various intensities of red, green, and blue
(the combination of which makes up the required hue, saturation, and
brightness of the desired colors)
↳ iOS: Color and Color Spaces
In terms of visible color, there is no difference. Both are regular white.
But technically, as you've debugged, they are two different objects which differs by the color space they use. One is created with RGB color space with all channels set to their maximum values. And the other is created with White color space (grayscale) with maximum white. On both spaces last value is the alpha value.
Below white color should satisfy your condition since it's using RGB color space.
UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
Why does Xcode have two different value of same color in storyboard
and code?
That's really not easy to answer. From storyboard, even if you use the grayscale slider to create white. It converts it to built in storyboard white which is RGB. That's just the way it is I guess.

Xcode: Launch screen changes color without premission

After adding launch screen, I discovered the color of it is slightly different than what I specify, I chose R:31,G:174,B:240,A:1, but I noticed it is slightly a different color on the device (I took a screenshot and used a color picker to determine what color it is exactly), this drives me crazy, what can I do?
try setting the numbers over 255.
so:
UIColor(red: 31/255, green: 174/255, blue: 240/255, alpha: 1.0)
RGB is based of 255 and need a floatNumber.

Add a color picker to an iOS app

I'm trying to add a color picker to my iOS application, using Xcode 5. It appears that Xcode offers a color well via the Palettes Panel of Interface Builder, but I can't find the Palettes Panel (nor can I find any documentation of it online beyond that link).
That link also suggests an NSColorWell can be added programatically. I'd prefer to go the Interface Builder route, but if that's not an option sample code would be welcome.
I had the same question as you. It's unfortunate that there is no built in color picker for iOS. The other answers here and for similar questions mainly use third party libraries or projects. I prefer to avoid all the third party stuff whenever possible, so that leaves us with...
Make your own color picker
There are many ways you could do it, but here is a simple example to show the concept. I set up my story board like this:
It has a UIView (grey here) to show the chosen color, a UIImageView to show the color choices, and a UISlider to choose the color. I used the following image in the UIImageView:
I made it from the colors of a 12-spoke color wheel using a screen shot and Gimp's color picker tool. Gimp is also useful for getting the color hex codes we will use later.
Set the min and max values for the Slider to 0.5 and 13.5. Converting the slider values to integers later will give one number for each of the colors in our image. Starting at 0.5 rather than 0 makes the slider color change location match the image better.
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)
}
}
Now if you run it, you can choose the color by moving the slider back and forth.
Variations
Position the slider on top of the image and set the track tints to transparent. This gives it the feel of a custom UI without having to subclass anything.
Here is another image with lighter and darker variations of the example project image.
let colorArray = [ 0x000000, 0x262626, 0x4d4d4d, 0x666666, 0x808080, 0x990000, 0xcc0000, 0xfe0000, 0xff5757, 0xffabab, 0xffabab, 0xffa757, 0xff7900, 0xcc6100, 0x994900, 0x996f00, 0xcc9400, 0xffb900, 0xffd157, 0xffe8ab, 0xfff4ab, 0xffe957, 0xffde00, 0xccb200, 0x998500, 0x979900, 0xcacc00, 0xfcff00, 0xfdff57, 0xfeffab, 0xf0ffab, 0xe1ff57, 0xd2ff00, 0xa8cc00, 0x7e9900, 0x038001, 0x04a101, 0x05c001, 0x44bf41, 0x81bf80, 0x81c0b8, 0x41c0af, 0x00c0a7, 0x00a18c, 0x00806f, 0x040099, 0x0500cc, 0x0600ff, 0x5b57ff, 0xadabff, 0xd8abff, 0xb157ff, 0x6700bf, 0x5700a1, 0x450080, 0x630080, 0x7d00a1, 0x9500c0, 0xa341bf, 0xb180bf, 0xbf80b2, 0xbf41a6, 0xbf0199, 0xa10181, 0x800166, 0x999999, 0xb3b3b3, 0xcccccc, 0xe6e6e6, 0xffffff]
Use an array of UIColors to avoid having to do the hex conversion.
Could use multiple UIViews rather than an image, and then set the colors directly from the array.
Further study
Color Theory For Designers, Part 2: Understanding Concepts And Terminology
Color Theory For Designers: Creating Your Own Color Palettes
Simple swift color picker popover (iOS)
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:
There is another cool color picker made by kartech. It has awesome UI for the selection of colors. Moreover you can mark colors as favorite. Link is here.
Screenshots:
If your app has a minimum deployment target of iOS 14, you can use the built-in UIColorPickerViewController.

Resources