Design UISegmentControl - ios

I'm having a segment control design like this
How to design my segments so that the selected one should look like the "ALL" like in the image above. What I could think of to use different images on selection but if I do that then some part of the curve which is going in "Others" won't be visible. Any suggestion on designing UISegmentControl like this ?

I have two suggestions:
Find an alternative approach that avoids this.
A lot of apps try to add delight by designing custom components and UI when actually it doesn't really add that much to the app. At worst you might frustrate people by using non-standard components that don't work the way they expect, or increase cognitive load as they're trying to use you're app.
Go 100% with a custom subclass.
Don't just settle for setting a static background image, but invest in creating a component that not only looks like this in a selected state, but also provides animations as people change the selected item.
This is going to be a fair amount of work, but would be something like this:
subclassing UISegmentedController -- it provides the base of the functionality that you're looking for which is good;
adding a new CAShapeLayer as to the controls background layer
figuring out a dynamic bezier curve that can update for all your states (will probably end up having control points for each segment) you might be able to do this by hand, but I'd have to use a tool like PaintCode to generate the bezier curve code, and Illustrator to make the initial curve
add listeners for event changes of the segment changing, and recalculate the curve control points as needed
The positive note of this is that the path property on CAShapeLayer is animatable, so when the segment changes and the curve updates the animation will probably be the easiest part!

Related

CALayer or other technique to actually modify the colors of layers behind, rather like clipping

Summary, in iOS how to have a view that modifies the pixels of all the views behind it.
Say you have a view, well any views, but let's consider a collection view which happens to just be some color blocks:
Say we added a view on top, CleverView, which either just blocks that view (so, white - trivial) or even "cuts a hole" in that layer (relatively easy to do, google).
No problem so far: so here's CleverView just a white square:
But what if we want to do this:
CleverView is changing all the saturation below it,
Or perhaps this:
CleverView is changing the hue or whatever below it.
Note that in the examples it's working in a pixel-wise fashion, it's not ("just") flagging each collection view cell to change all of the cell color.
So ideally CleverView would do this to anything at all that happens to be behind it (ie, whatever bunch of views it covers or partly covers, hence the collection view example which is just 'many views).
Naturally both the underneath stuff, and the shape of CleverView, can be animating, moving, in real time.
Is there a way this could be done in iOS?
(In that specific example, what I do is just, have two of the collection views: the bottom one and the top one has the new color values. Simply with care clip the top one to achieve the effect. But obviously that's not as Clever as a view that actually "modifies the values of all the pixels behind it".)
{Note too that, obviously, you can just make basically a screen shot, munge that image, and show it; not really a great solution.}
The CALayer has a property backgroundFilters where you could normally add a CIFilter that would do the job. But, documentation states that
Special Considerations This property is not supported on layers in
iOS.
That's annoying, but that's all that we have. Probably, it's due to performance considerations.
I would suggest to look into SceneKit, there the primitives are very similar to CoreAnimation, also animatable with CAAnimation, but provide advanced tools to configure and control many more aspects of the rendering.
For example, SCNNode has filters: https://developer.apple.com/documentation/scenekit/scnnode/1407949-filters?language=objc

graph paper interaction in swift/iOS

I'm picturing a graph paper like interface, as you click on any given box within the graph it gets colored in. I'm doing this to draw rough shape outlines.
My question is what is the best approach to do this? Draw the lines for the graph and track where the touches occur and color accordingly? Make some array of buttons? Maybe using spritekit?
I'm not too worried about efficiency as I'm not doing anything too complicated but I'm just trying to find some common design ideas behind it.
Something visually similar to this.
You can accomplish some pretty complex behaviours with a UICollectionView and a custom layout. UICollectionView is nice because it manages taps and drawing each cell individually, which should vastly simplify things for you.

In OpenLayers3 how would I prevent a feature from moving in front of other features when selected?

The hierarchy I'm using looks something like this:
FRONT
1 - layer with several features (e.g. point data)
2 - layer with several features (e.g. path data)
3 - layer with several features (e.g. region data)
BACK
When the user selects a feature in layer 3 based on an ol.interaction.Select the default behavior is to render the selected feature in front of layer 1. How can I prevent this re-ordering?
I had a nearly similiar problem, when i selected the region - the points and other vector geometries were hidden behind the selected feature. In my usecase an special styling with transparent filling was the solution.
If you want a solution based on the layer rendering i would suggest to handle it with the ZIndex. The ol.interaction.Select doesn't provide a setZIndex but if you take a look on the source code (https://github.com/openlayers/ol3/blob/v3.13.0/src/ol/interaction/selectinteraction.js) you can see that the interaction save the selected feature in an unmanaged Layer which you can access on different ways (map.getLayers().getArray().forEach .... or sth) and i'm sure there you can set the ZIndex. Note default zIndex is 0 and a higher Index will render the layer above and lower one.
Here's how the select interaction works in ol3. The selected feature is marked for being skipped in rendering. In other words, it disappears from the original layer it comes from upon re-rendering after being selected.
It is then added to an other layer that is actually not added to the map using the conventional map.addLayer method, but set to the map using layer.setMap. The layer ends up being drawn on top of all the others, resulting the "selected" feature to be on top of everything else.
This architecture was decided to improve performance. However, you can easily achieve what you want, i.e. have the clicked feature stay where it is and change its style, by simply using the map.forEachFeatureAtPixel method and implement your own concept of selection there. It would be slower, but simple enough to accomplish what you want.

Drawing a grid of circles in xcode/swift

How would I go abouts getting an effect in a view controller like the wonderful work of art attached in the following link?
Circles
I do have some idea, ranging from actually using ASCII text (I know, super wrong way) to a collection view of pictures, to what I suspect is the "right" way, done with core graphics. But I am asking in case there is a super easy/right methodology I will one day discover and facepalm.
You are correct that there are two primary ways for you to draw a grid of circles.
The primary way is to draw them using UIBezierPath or by using a collection view of images of circles.
For simple shapes, it is recommended that you choose the first option simply because your choices of circles aren't restricted by your images.
Here is a link for you to get started.

Creature animation

I am looking into making an iOS app that has little creatures. I plan on having these creatures grow and change shapes based on user interaction. So the creatures could end up looking very different based off what the user does.
My problem is animating these creatures. I have dealt with simple animations in the past with cocos2d, but nothing like this.
How can I animate these creatures being different sizes and shapes without having my graphic designer draw every possible image that could be used. In the game spore a user can create an animal of whatever shape or size they want and these animals animate. My question is how can I do something similar in 2d? I know this can't be a simple answer, but a point in the right direction is all I am looking for.
You could use some CGAffineTransforms to scale your drawing and custom filters with Core Image maybe to change the color.

Resources