Desaturate a live UIView layer (not a UIImageView) - ios

I'm wondering what would be the best way to desaturate a UIView—particularly, a UISliderView with custom appearance applied to it. In iOS 7, the standard controls fade out their tint colors when another view appears over them (for example, a share sheet or UIAlertView), but since mine is built from UIImages, the tint property doesn't apply to it, and they remain saturated.
Is there a good, easy way to desaturate this, short of re-applying a new UIAppearance for it? (If I were to go that route, would I even be able to animate the transition from colored images to greyscale ones?)
Thanks in advance!

Related

Custom Drawn UIButton

I need to have a circular UIButton that draws a custom color in the middle, along with an outer ring that is drawn as the default tint color (similar to a UIColorWell).
I've tried a few different approaches:
Using a multicolor SFSymbol: This would be an elegant solution, but as far as I can tell there's no way to apply the tint color to just a part of the image while setting the center to be a custom color. Either the entire image is tinted, or the image is drawn as the default colors set in the symbol file. Also, I need to support iOS 14, while the new hierarchical options that may allow me to accomplish this were added to iOS 15.
Setting various layer properties (ie, cornerRadius, borderColor, etc): This works and may be a decent fallback solution, but I'm unable to get the look that I'm going for (namely, having a transparent ring between the outer border and inner colored circle).
If there's a way to use either of the above options, please educate me! Either one seems like a better solution than:
Overloading the draw function: This is the option I'm going with at the moment, as it allows me to have complete creative control over the look of the button. The rest of this post will be regarding this method.
So far I was able to get the button to be drawn exactly as I wanted. However, I am unable to figure out how to draw the button appropriately with regards to various state changes.
For example, if a popover is displayed, all of the normal buttons are automatically redrawn as disabled. My custom button, however, isn't redrawn so I am unable to respond to the state change.
Same thing with tapping on the button - normal buttons are briefly shown in an emphasized color but my custom button doesn't respond.
Does someone have an example as to how to support overriding UIButton drawing with various states?
I was able to get the desired behavior by overriding tintColorDidChange in order to trigger a redraw of the button. Now I am able to draw the outer ring in the correct color (including grayed out when a popover is displayed) while maintaining the desired inner color.

iOS - blurred view with moving colors (like siri on iOS 9)

I'm writing an iOS application, and I would like to use a view that has randomized moving colors in the background, much like the view that is brought up when you use siri. The view used for siri seems to be slightly darker than a standard dark UIBlurEffect and there are random colors added that move slowly around the view whenever queries are made.
Below is an example of the background I'd like to create. There's some red in the top right of the blur and some green in the top left. Plus some light purple or something at the bottom.
siri query view
The colors fade and new colors are added every queries, I honestly have no idea how to accomplish this, so any help that anyone has would be great.
Also, I'd like the answer to be in Objective-C if at all possible.
You refer to UIBlurEffect and it is key here. It provides a blur over a background, but doesn't specify what that background is. So, create that background to be a set of coloured views which appear (fade in perhaps), move around and then disappear. How you control the start and end location and the path the views follow is up to you. The effects view will apply the blurring for you and you can add whatever content you want in the foreground to the content of the effects view.

How to specify vibrant appearance for secondary Today Centre widget text?

I am working on my first Today Centre widget, which simply consists of three labels on the default storyboard. It's working fine, but I read in the iOS Human Interface Guidelines that secondary text should "use the system-provided vibrant appearance" with notificationCenterVibrancyEffect.
What's the correct way to add this vibrancy effect to my two secondary labels? I've read about UIVisualEffectView, but it's still not clear to me how to use it for this purpose. I don't think I want to put a blurred view behind my labels because Notification Centre already blurs the background.
UIVisualEffectView when configured with a UIVibrancyEffect is meant to be used as a container—just drop your labels in its contentView and you’ll get the appropriate appearance on top of the Notification Center blur. The text color doesn’t matter; when it’s added to the contentView it gets special treatment and effectively always renders with the same appearance, though you can still adjust the alpha of the view (not of the text color) to make it more or less prominent.
good day, first of all u should use a correct view hierarchy, when U add some objects in your VisualEffectView example:
UIVibrancyEffect used in combination with UIVisualEffectView, adjusts the colors of the content to make it feel more transparent. UIVibrancyEffect can blending some objects
with the background example:
More particularly to your question(https://stackoverflow.com/a/25392645/4912496) Apple recommends to use vibrant effect for secondary text, because its simply beautiful for example(apple native app use vibrant effect, and Sports.ru don't use it):
But, some apps don't use this effect...
To ensure that your widget gets the vibrancy effect that’s appropriate for displaying items in the Today view, use notificationCenterVibrancyEffect.
Some info. https://www.omnigroup.com/developer/how-to-make-text-in-a-uivisualeffectview-readable-on-any-background

turn off UIPickerView gradient

I created a UIPickerView that I would like to not have that fade on the edges.
First I thought that must be some kind of gradient overlay so I recursively hid all UIImageViews within the UIPickerView and also set all layer.contents to nil. Setting a background color different to white to the picker view reveals that the fade cannot be an overlay, since the labels in the picker view now fade to the background color.
Does anybody have an idea on how to find that layer mask and turn it off?
EDIT
I just checked if there are any CALayers with masks, but there are none.
This is not exactly the answer to my question but at least a solution. I found a custom (horizontal) AKPickerView on GitHub which is available for Obj-C and Swift (1.2 and 2.0). This View has an undocumented property maskDisabled which does exactly what I need.

What effects does iOS add to UIBarButtonItem images?

What effects does iOS add to UIBarButtonItem images? I want to put three of my "buttons" in a UISegmentControl segment to visually group them. However, UISegmentControl does not add the same effects that UIBarButtonItem does.
There seems to be a black shadow just above the image in the UIBarButtonItem, but I haven't been able to match it through experimentation.
I don't mind doing this in code or in a graphic editor, though I'd prefer code. :)
Apple's docs say this, which I assume is the same basic approach:
Toolbar images that represent normal and highlighted states of an item derive from the image you set using the inherited image property from the UIBarItem class. For example, the image is converted to white and then bevelled by adding a shadow for the normal state.
My main concern is matching the shadow; the base colour is not black, and I don't know the opacity.

Resources