iOS Question iOS Switch Centering

Mike1970

Well-Known Member
Licensed User
Longtime User
hi everyone, i'm trying to center properly a native ios switch in a panel, but i don't get it done in a reliable way.


in the designer


How can i manage to get it done properly?
Thanks in advance
 

Sandman

Expert
Licensed User
Longtime User
It looks to me that you have a problem with your anchors. On top of my mind: If we assume that swDBClean has the dark thing as parent (can't read the name), you wouldn't have to have the top anchor for the switch. (Because they will both stay the same height, and the switch is centered, as far as I can see.)

Can you try to make sure the switch have correct parent and remove top anchor and see if that solves the problem?
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
Can you try to make sure the switch have correct parent and remove top anchor and see if that solves the problem?
Thanks for answering.

Uhm how can i remove the anchor? it is not possible in B4i, at least i can set it Top&Bottom or Bottom, the parent is correct
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
Yeah, I think I was wrong there, sorry. My last suggestion is that you look at your designer scripts, and code, to make sure you don't change the height of the parent. Looking at your screenshots, it doesn't seem as high as it is in the designer. It does, however, look as wide, so I'm thinking that there is something adjusting the height. That would also explain why the switch have correct distance to parent top, and not to parent bottom.
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
Actually the only line in the designer is this
B4X:
'All variants script
AutoScaleAll
swDBClean.VerticalCenter = pnlDBClean.Height/2


The sizes are not the same because of the AutoScaleAll

The problem is that the switch is NOT centered in his hitbox itself
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
Here you a are a more explanatory picture

Watch the hitbox, the switch is positioned in the top left corner... is that the problem

i can center the hitbox, but not the switch..

 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
i can center the hitbox, but not the switch..
Aha, in that case I think it's even simpler. The switch doesn't resize, so the hitbox needs to have the exact height of the switch to end up in the middle.

Dirty suggestion (in case you don't already have this info elsewhere): Take a screenshot on your phone, open picture in image editor and measure height of switch. Use that as height for the hitbox.
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User


Yes ahaha, at the moment i increased the height dips one by one, until i founded the correct hitbox height. ahhaha
But i don't know if it will change by changing display size.. so i don't know if this is reliable
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
i don't know if this is reliable
I wouldn't count on it. Just imagine a future OS upgrade that changes the design of the switch slightly, and height with it.

The correct way (assuming this last strategy is correct, in the first place) would be to do some code magic and ask the OS for the height of a switch. I have no idea how to do that, sorry.
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
exactly, but unfortunaly i don't know how to do those things ahhah, i will wait for an answer from a B4i Magician
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
i will wait for an answer from a B4i Magician
If this is a strategy you believe in, the best thing you could do is search for info on Stack Overflow (and the like) on how to get that info in the first place. Then post a new thread asking how to convert that to B4i. That would make things a lot easier for the people who know how to do those things.
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
mmm something i've found before actually.. i will make a post for that
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…