Trouble with auto layout constraints with iPhone 5 and iPhone 6 - xcode6

I am currently having some trouble auto layout constraints. I have 5 labels arrange horizontally like in the example below:
Ex. [ID Name Sex Age Occupation]
(supposed the Brackets is the edge of the screen
It look nice in the iPhone 4.0 inch. but it not look what I want in the iPhone 4.7inch and the 5.5inch.
Ex. iphone 4.inch look [ID Name Sex Age Occupation]
Ex. iphone 4.7 inch look [ID Name Sex Age Occupation ]
Ex. iphone 5.5 inch look [ID Name Sex Age Occupation ]
There is some space at the edge for the 4.7 inch and the 5.5 inch.
Please help me how to make it all look the same as iPhone 4.0 inch.

To make this layout work on all devices, you will need to set a static width for the first 4 labels and let the fifth one resize so that it fits the superView.
The constraints should be something like:
First Label : leading space to container + width + horizontal space to 2nd label
Second - forth label : width + horizontal space to label
Last label - trailing space to container
You will need for all labels also vertical constraints, but I supposed that is already working.
Let me know if you need more help

Related

Additive Color Mixing (Blending) of images in Universal Windows XAML

I have a image of a scene with default lighting. Let's call this image_baseline.
I have another image of the same scene, but an extra red spot light is added. Let's call this image_with_extra_red. Some surfaces show a lot of red, while other surfaces remain unchanged since the red spot light does not uniformly light the scene. No place in this picture is darker than the original since the default lighting was not removed, just a red spot is added.
I have another image of the same screen, but extra green light is added just like the above. Let's call this image_extra_green.
Likewise, I have image_extra_blue.
Now I have 3 variables. Percent_of_extra_red, percent_of_extra_green, percent_of_extra_blue.
I would like to add to image_baseline the proportions of the extra color lighting.
Pseudo code :
red_adder = image_with_extra_red - image_baseline; // now red_adder contains only the incremental effect of the red light
green_adder = image_with_extra_green - image_baseline;
blue_adder = image_with_extra_blue - image_baseline;
new_picture = image_baseline + (Percent_of_extra_red * red_adder ) + (Percent_of_extra_green * green_adder ) + (Percent_of_extra_blue * blue_adder )
The purpose of the above is to allow the user to control the intensity of the added red, green or blue spot light.
Hoping this can be done by overlaying 4 pictures in XAML and binding 3 variables Percent_of_extra_red , Percent_of_extra_green, and blue.
If it makes it easier, red_adder, green_adder, and blue_adder can be constructed offline with some graphic sw.

Fixing two uiviews size based on screen width & height in storyboard IOS 7

Please tell me: how to do the below logic in storyboard using constraints.
Fixing two UIViews(minimum :130x80) in screen. The center gap between uiviews always 20px.
screen:
20px View1 20px View2 20px
Thanks in advance!
Add the Leading Space Constraint between view1 and the screen : 20px
Add the Trainling Space Constraint between view2 and the screen : 20px
Add the Horizontal Spacing between the views : 20px
Add the Equal Widths between the two views.
And to not have errors, add the top + bottom constraints, or the Vertical center + Height on view1
Finish by adding the Same Top + Same Bottom constrains on view2.
Enjoy ;)
EDIT :
Huh, I forgot that your views have Width >= 130.
Then, 130 + 130 + 20*3 = 320, which is the width of the screen on iPhones <= 5S.
And when you use the leading/trailing space constraints, iOS will start to count from 16px, then Leading Space 20 will give you X = 36, then you'll miss some place.
The solution is to set X = 20, and then pin the Leading space, or modify Leading Space value from 20 to 20 - 16 = 4. Same thing for the Trailing Space of the View2

xcode - autolayout - prevent overlap of logo + input with footer button

I am having trouble preventing the text inputs from overlapping the footer button.
The footer has been anchored to the bottom of the screen. All the elements up top (logo, title label, and 2 input boxes) all have relative constraints. I try to add a constraint between that last input and the footer button but it pushes the footer off the screen on the smaller iphone.
What do I do??
https://github.com/civilordergone/taskfort_ios
Your issue seems to be in landscape only (I ran your code), where you have, for example, 320 points of vertical space, and an image (128pt), a text label (120pt), two text fields (30 each, for 60pt in total) and a 30pt button at the bottom. Already that's 338pt used, and we haven't accounted for the vertical spacing between your objects.
There simply isn't enough vertical space for all of these items to be vertically positioned while retaining their heights, so something has to be flexible: something has to be able to be vertically shrunk/compressed. Your logo and app name (Taskfort) are two candidates.
Here are some of the changes and/or points of consideration:
An ImageView with a height and a width equality constraint will always be that size, but for your layout, it has to be able to be compressed. I removed the height & width constraints and added an Aspect Ratio constraint, so the logo keeps its aspect ratio, but can now scale. I added a relationship constraint between the logo's left side and the left side of the Taskfort label.
The image has a relationship to the top of the screen, saying it must be equal or greater (not less than) to 0. This just means "the image can't be pushed off the top", which "less than" would allow it to be. (For example, if the image is pushed off the top by -40 points, that's still "less than 20").
The image has to be allowed to be vertically compressed. There is a property for "Vertical Compression Resistance" that was 250, and is now 249. By setting it to 249, we're saying "If something has to give way, vertically, this object can be compressed." Since we defined an aspect ratio constraint, if it does get compressed vertically, it'll be reduced horizontally by a proportionate amount so as to maintain the proportions of the logo.
To prevent the text fields from overlapping, their relationships are set to "equal or greater than". Same for the Username text field to the label.
The challenge was in defining the relationship between Password and the Create Password button at the bottom. I added a constraint that says their vertical distance must be greater than or equal to 20. This has a priority of 1000 (by default), so at all times, you get 20pt or greater between those two. Without this, your password field and your button overlap.
While step 5's constraint solves the overlap problem, it creates a new one in portrait orientation, where the password is now 20pt from the button, instead of being lovely white space. To fix that, we add a second constraint between the password field and the button, and specify that the vertical distance is to be 228pt between them both. Now that creates a constraint conflict because you now have two constraints that are both trying to define the vertical relationship between the button and the text field. The 20-pt one is required, it has to be there. But the other one is just a "nice to have, if we can fit it".
So you set the priority of the new one (the 228pt) to be low, such as a Priority of 250. Then the layout engine will use the required one (must be 20 pt or greater) and then it sees the other one ("make them 228") and it tries to do that. If it can't, such as in landscape, then it doesn't do it and doesn't complain, because you have the other constraint already that provides positioning information. If you're in portrait and you have enough space such that it can also apply the low priority constraint, then it'll do that too, and your portrait layout now gets a bigger gap between top and bottom.
When testing these layouts, use the Assist Editor in Preview split-screen mode so you can see the affects of your changes without needing to run the simulator. Here's a guide on that.
Sounds like you're using an equality constraint, such as "the distance between lastInput.bottom and footer.top equals 20". Instead, try an inequality operator, such as "the distance between lastInput.bottom and footer.top is equal or less than 20".
The attributes inspector for a constraint can let you change an equality to an inequality. Alternatively, you can double-click the constraint line (the UI in the storyboard editor) to get a quick pop-up for that.

character is of string is always changing the position when ever I change the string value by using CCLabelBMFont

I update the score label when I'm playing my game and I display it by using CCLabelBMFont, when the score changes, each character of the score label always change the position of the label.
I want to keep it the same position!
Example: 00:01 take small space than 00:50; when the text change the CCLabelBMFont reposition the text again. help me , how to keep the same position?
Your bitmap font was created from a true type font that has a variable width.
Only fixed-width fonts like Courier will give you the same string width for the same amount of characters in the string. Strings drawn with non-fixed-width fonts will have varying width depending on the characters in the font, ie a 'w' character has greater width than an 'i' character.
Open FontBook.app (it comes with every Mac) and in the Collection panel select "Fixed Width" to see only the fonts with a fixed width. On my system I have these fixed width fonts installed:
FYI, Monaco is the default font used by Xcode.
It is hard to tell by the question, but my guess is that you are talking about the actual positioning of your label changing, meaning your alignment is not what you want it to be (justified left instead of justified right for instance).
Left Justified:
test
testtest
Right Justified:
test
testtest
If this is what you are talking about, you can change the text alignment by changing the nodes anchor point.
// for right justified
label.anchorPoint = ccp(1, 0);
When you are saying "always changing the position", do you mean "left side isn't staying in the same place"?
CCNode class has anchorPoint property, which determines which point of this node is "pinned" to the point in node's parent. Anchor point of (0, 0) means bottom left corner, (1, 1) - top right, (0.5, 0.5) - center. All positioning and transformations take place around anchor point.
Set anchorPoint property of your label to mean the point which you want to have "pinned" when content size of label changes. Examples:
if you want top left corner to be stationary:
label.anchorPoint = ccp(0, 1);
if you want the middle of left side to be stationary:
label.anchorPoint = ccp(0, 0.5);

UIButton's titleLabel has 5 points offset for one of fonts

I am developing an app, that has support for customizing fonts, colors etc. in design time.
You just swap a plist and the app has a different style,color,s etc..
This works, i need to have it like that . So far so good.
Some buttons have titles. I use two different custom fonts for two different builds.
The problem is, using the other font causes the titleLabels in all buttons to be offset 5 point to the TOP.
I can't use some "hacky "way to move the offset 5 px up. Since it wll coause the first font to be offset 5 px up.
I am not really sure if the problme is in my code, or in the source font file.
The label is centered horizontaly and verticaly. Is there any other way to generalize the code so that it would handle that offset difference?
compare like this:
CGSize firstStringSize = [myString sizeWithFont:firstFont]; //get size for first string with its font
CGSize secondStringSize = [myString sizeWithFont:secondFont]; //get size for second string with its font
if(!CGSizeEqualToSize(firstStringSize, secondStringSize)) //checking for both are not equal
{
if(firstStringSize.height > secondStringSize.height)
//secondStringSize offset 5 px
if(secondStringSize.height > firstStringSize.height)
//firstStringSize offset 5 px
}