How to resize between 3.5" and 4" screens (dynamic constraints in autolayout?) - xcode

I have one view filling the screen with a background image. Other views (text fields) are in exact positions (the background image includes the text field background images). When I change from 3.5" screen to 4", the text fields don't change in the same way that the background resizes. The bg image simply resizes to fill the screen, but the text fields jump out of alignment.
Is there a way to have two sets of constraints, one for each screen size? or is there a way to have views resize proportionally to another view?
EDIT:

Is there a way to have two sets of constraints, one for each screen
size?
Yes, by adding constraints programatically and checking [[UIScreen mainScreen] bounds] to get the screen size.
or is there a way to have views resize proportionally to another view?
Yes, you could set this up in interface builder. But it will be hard to manage, I would manage the constraints manually in code since you are using a custom background image the textviews need to position exactly

You're going to struggle to get these things to line up properly with the text view backgrounds being part of the background image.
You should amend your image assets and use the background property of UITextField to have an actual background image, and remove the boxes from your main background image. The icons could be separate images as well.
Failing that, it would make more sense to have the image stretch underneath the text boxes rather than on top.
Your layout is doing what it should do based on your description, but the image isn't stretching in the right way. In your screenshots, username is always the same distance from the top, and the others are the same distance from the bottom, but that isn't how image stretching works. I don't know how you've set it up but it would make sense to have a single image the size of the 4 inch screen, which has the bottom cut off for 3.5 inch devices, and constrain everything from the top.

Related

React Native bunch of buttons on top of background image

I have a background image and I need to add bunch of oval buttons or images on in my case the "greenish" buttons on top of the background image, that I can click in each one of them and call a function passing a parameter. Please look on the screen shot and let me know how I can position every one of the buttons on top of the image and access them with a click (onPress). I guess the only way is using flex box but I couldn't figure out the style for it.
Thanks
Just style all the green buttons on relatively to the image's boundaries with position: absolute. Percentage values for positioning should work, if your image scales properly on screen size change.

Autolayout just not working for every screen size

My app is a game and the menus have many labels and buttons and I cannot get all of the different screen sizes(iPhone 4/5/6/6+) to look acceptable from the same set of constraints.
Is there a way that you use to synchronize all the views together to look the same on all different screen sizes?
The project is locked to only portrait so I don't need to consider rotation.
For Autolayout, you
Consider the screen sizes you want to support.
Which view/buttons/labels/imageview etc you want to remain fixed while in
different screen size.
Which view/buttons/labels/imageview etc can be scaled to fit the screen.
Now if by scaling the things you can fit on the screen then you are good to go. But if you still can't find way then you would probably need to you use scrollview and and add a UIView (let's call it content view) to it put your all stuff in it and constraint them vertically all the way from top to bottom.This video can help you if you want to use scrollview
https://www.youtube.com/watch?v=UnQsFlMGDsI

cocoa mac osx grid display of images of different sizes

what i'm trying to do is displaying a set of images in a grid like fashion but with different sizes as for images in landscape or portrait position, this excludes using the NSCollectionView because the item prototype's size can only be set once...
i'd go and add subviews programmatically to a scrollView but this yet again when the window's size changes and the scrollView get a bigger width, there will be just blank spaces on the right side...
you can checkout the image below for a better understanding...
http://i.stack.imgur.com/NVJjP.png
thanks in advance you guys...
what i ended up doing was implementing a purely mathematic algorithm where i calculated the (x,y) position for every new added photo depending on the previously added photos and it did a pretty good job... the container holding the photos was embedded in a scrollView, needless to say that i had to calculate the height of this container as well.

masking with an image in iOS

I'd like to take an image and use it as a mask for a view on which I add numerous image views. I know of the quartz CGContextClipToMask() call but what would be the best way to approach this? Can I override the drawRect method of a container view, call CGContextClipToMask() within it, and then expect its subviews to adhere to that clipping region? It doesn't seem to work.
Do I need to instead add some blocking mask image over top?
Instead of subclassing or overriding drawing functions, I chose to overlay the images with an image that had transparency in the viewable portion. i.e., if my 'surface' was an image of a parchment, and I aimed to draw a bunch of images on it. I would have the parchment image, then a container UIView for any images to be put on that parchment, then a masking image over top of that which was the original parchment image but with the parchment itself converted instead to full transparency, while the surrounding area is left exactly as the background the parchment is on (then all other UI widgets over top of that).
This seems a viable solution in all cases except if one were to need some image to visually animate around and behind the parchment (not my case).

How to create badge with image in sidebar (like in Mail.app)?

I'm creating NSOutlineView with custom cell class (extending NSTextFieldCell) which should display image-based badge (something like in Mail.app while working offline).
Is this approach appropriate? I've created NSRect with oval shape inside (with bezierPathWithRoundedRect:xRadius:yRadius: method) which is filled with color depending if window is active etc. I've prepared a image with a symbol I want to dispay (grey on transparent background) and draw it inside a rect using drawInRect:fromRect:operation:fraction: method. I'm able to choose such a NSCompositingOperation to have an image displayed properly when background is blue or grey but not on white background.
May it be related to the brightness of the image is (or is it another image-related problem) or maybe should I do something totally different?

Resources