Im testing some stuff for an app in SWIFT. My goal is to have the full screen covered in blocks, so it give a 100% width and height. but for some reason, theres always 1px or 2px spacing.
I think its because when i screenWidth is 320px, and I try to split it with 3 blocks, that would give 106,6666px pr block which is not possible.
Anyone got a good idea how to solve this? Should i maybe just add 1px if the number is uneven?
Related
I'm customising the UITabBar in my app. I have 3 tabs so when one is selected it has a background that spans 1/3 of the width of the screen. The only problem is, the screen is 320pt, so divide by 3 and we have a non-integer, thus leaving this horrible gap on the end. I set the background images of the selected state to 106pts and then tried it at 107pts, but that didn't help at all. Here is a picture of the TabBar demonstrating the nasty gap at the end.
It's quite hard to see, but it is there. Does anyone have advice as to how I can get rid of it. This is a subclassed UITabBar so obviously I can make modifications, but I would prefer to keep the fix as simple as possible.
Regards,Mike
Think I've got a little fix, but it's not particularly elegant. I increased the UITabBar width to 321pts so an extra point is being drawn off screen, causing a tab (not sure which one) to expand in size, thus filling the gap.
Give the central element the width of deviceWidth / numberOfTabs + deviceWidth % numberOfTabs, and the others deviceWidth / numberOfTabs. This way the central element will be 108px and the others 106pxs.
This question already has answers here:
Can you have a 0.5px border on a Retina Display?
(10 answers)
Closed 9 years ago.
I have a quick question, as all of my searches have turned up app design and not web design answers.
When designing for Retina, what should I put in my CSS to make a 1px horizontal line appear as just that - 1px? I don't want it doubling up, but I also can't make it 0.5px apparently.
Or does it render pixel-specified borders as it should?
Everything I've looked into so far just makes it so much more confusing.
I'm assuming from your tags on the question, that you have a 1px border created in CSS. There is no need to adjust the border for high density displays. When the border is rendered by the browser, whatever calculations that need to be made for it, will be. So, you'll get a crisp 1px border in any scenario.
Unfortunately, I cannot locate a resource that states this explicitly. However, I know from my personal experience (developing websites, including mobile) that I never make any adjustments to border thickness for high density displays. I only do this for graphics.
This is one of many reasons why using CSS to create your graphics is useful.
On the web page, I'm scaling all of my images by 50% with CSS to make them look sharp on retina screens but that doesn't work for tiled images, there seems to be no way to scale a tile background image so that it will be sharp and not doubled sized on the retina screens. Sorry if this question is confusing.
Setting background-size: 150px 150px; for a 300x300 background image seems to do the trick. Note that background-size: 50%; will not do what you might expect, as it sets the width and height to 50% of the parent container.
I haven't worked with Retina displays, but I would imagine it would be better to create an alternate background image with higher resolution for them.
For the problematic behavior, try resizing the window of this web app. Thought the header and boxes stop being resized after a minimum dimension, the background image continues to position itself at the center of the page, which looks really stupid.
Here's the relevant code for the background image:
body{
text-align: center;
min-width:1000px;
min-height: 600px;
background: url(../images/road_newtry_tile4.jpg) 50% 50% fixed;
}
Even though background-position isn't nixing the min-width and height (ie, the window will stop resizing after predetermined dimensions, it continues to center the background image.
Why is it doing this? How can I prevent the image from re-centering after certain a certain point?
it is doing it because the 50% is relative to the size of the browser window. A fix would be to instead have the background image on a wrapper div, which has the min-width and min-height set.
I've got the following situation, and I need some help...
Two divs, same size, same location, one on top of the other
Everything works as expected on desktop browsers
On the iphone/ipad a faint line appears around the border of the divs
This faint line is not always on all four borders. It changes depending on the location of the divs. It looks to be happening as a result of the two divs not lining up properly, but according to their style settings, they are of identical size and location.
You can see the results here: http://www.thoughtartistry.com
Any ideas?
I had a similar problem in a recent project where I had background image masks with different background color to colorize the resulting icons in mobile Safari. The problem was that when the page was scaled down by Safari, there was a line of the background color showing around the image, even though it should have been masked. I never found a way to prevent that leaking of the background color when the page is scaled down. It's clearly an error in mobile Safari's algorithms that recalculate the background and mask. I did find a workaround: I put an outline on the element with the same color as the background of the element's parent. The outline is outside the element and therefore masks the part bleeding out. If your element's parent has a pattern background that's drastic, this won't work that well, but if it's a solid color, it'll do just fine.
A negative margin is the only way I found to prevent this.
For example, if you have a faint horizontal gap between 2 divs, adding a top margin of -1px to the second div will make it overlap slightly and the gap will not reappear as the page is scaled.
Some situations (like image sprites or repeat patterns) may need a little more tweaking, but the general idea is the same. For a sprite, make sure there is no big color change within 1 pixel of the cropping border. The bleed is never more than 1 pixel, so a 1 pixel adjustment is enough.
The problem is not only with divs matching together, but also with image sprites.
I followed the advise in this thread of setting initial viewport scale to 1.0. The sub-pixel bug was gone, but then I tested my website on other devices, like Android, and realized a full size page is annoying, since users have to re-scale every time it's loaded. So I preferred to disable the scale and wait until Apple fixes it. Then one day I was thinking how to solve the problem with the margins of the page, and I came to this simple solution in CSS:
html {
min-width: 1024px;
}
Devices capable of this resolution, such as iPad in horizontal position, will set the document scale to 1.0. In my case this is enough solution, since I can show the page is working just right, and the sub-pixel bug is in Safari/iOS, which will be solved in the future hopefully.
It totally depends on one's situation, but in our case we use negative margins as proposed by this thread or a box shadow since outline only applies to all borders and ie. outline-bottom does not exist.
/*
* Prevent faint lines between elements.
* #link http://stackoverflow.com/questions/5832869
*/
box-shadow: 0 1px 0 red;
I also solved the iOS sub pixel gap issue (on a full screen site) by using overflow-x: hidden; to stop side ways scrolling & viewpoint scale to stop pitch zooming. I also had holder divs set at width: 101%; and all the elements/image divs inside set to float: left;. This means the sub pixel gaps are all on the left hand site but pushed out of view by the holder div set at 101% width.
Remove "clear:both" (if there is) from div below the gap.
I also had to solve this. If you are using Div's to define sections only then.
//background.css
.background-color {
background-color: blue;
}
.background-color div {
background-color: inherit;
}
I'd try playing with meta/viewport options, specifically setting initial scale to 1.0 and disabling user zooming.
https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/MetaTags.html