How to center align text in love2D vertically and horizontally? - lua

I want to display a text when a specific thing happens in love2d. Everything is working fine except the text displays somewhere away from the center. So i just want to know a way of center aligning text horizontally and vertically. Thanks in advance!

Horizontal aligning works best with love.graphics.printf(). Specify center as the alignment.
Alternatively you can use font:getWidth(text) to get the width required in pixels. love.graphics.getFont() to get the currently active font.
For the height use font:getHeight() or font:getBaseLine(), depending on where the vertical center should be.

Related

Xcode constraints not changing equally

I'm trying to format a home page of my app and want the distance in the middle of two buttons to stay the same while keeping them centred on the screen using alignment in Xcode. I've been playing around with the constraints forever and can't seem to get it to work. Currently, when on a smaller screen, it seems to favourite the right side editing before the left.
Current alignment settings:
What it looks like on small screen:
I’ve been playing around with the alignment setting forever.
Refer this video
Use stackview and it will make your life easy, i have center aligned the stackview. You can give constrains as per your need.

IOS adaptive layout using Autolayout

I am working on IOS app and its my first app to be build on IOS. I have good experience of developing Android apps. So I have gathered basic information and knowledge about IOS development. I am working on autolayout. But I am not getting it work completely. I have seen Some developers are working on code, But I just want to use IB as I believe there will be some way to handle this.
So looking for help, Please do not down vote my this post As I am posting this after trying almost everything I get on internet.
First take a look at what I have developed and what it is :
in picture there are different numbers of simulator such as Ipad pro 12.9, Ipone 8 plus and I phone se
What I have done so far:
I have taken the View (the white box in middle). I have made it center vertically and center horizontally.
I have set view height as 300 points, and width to match the superview with some margins
I have put the Text Fields for taking Phone and PIN from user and OK button as shown in picture.
Problem & what I want:
- The problem is view is center vertical and horizontal but not its
content are. I want this view to manage its height on the basis of
its content inside. so that It can be looked as center aligned
vertically. Right now its not center align vertically
- Secondly the problem is the width of text fields, as on Ipad they looks too bad. So I really want them to be look good on all devices.
Is there any solution for this using the adaptive/Auto layout? please help me that How can I get this using IB.
Try following solution:-
Fix the width of textfield.
For label use minimum font scale(search on google).
For width and height you have to use adaptive layout.
width = 70% of superview which means multiplier for your view will be 0.7
height = 60% of superview which means multiplier for your view will be 0.6
Refer to the image:-
Equal width with the superview
Set the multiplier as 0.7
#Android Teem,
For this you need to use SizeClasses along with the AutoLayout.
Below I am trying to give you solution.
use items structure as like below. Don't use another UIView inside main view. Instead user StackView. It automatically adjust contents inside it. For more just look for "UIStackView" on Apple Doc.
Next you need to add constraints to stack view as
Leading 10 (for x)
Trailing 10 (for y)
Allign to center (for width)
height stack view will automatically adjust.
Now double click on leading and trailing constraint will open size attributes. Click on "+" icon just before Constant. It will show you a pop up. add Regular Width Regular Height for iPad and set values as 200 (I have give 200, you can give based on your calculation and requirement). this will show like below image
Now Either run or check from preview for all screens. you will get desired results. my changes show result as below
Happy Coding
Here is what you need to do. Go to the storyboard
Right click on the white area of the screen and drag the cursor to the green area.
Few options will appear, select Equal Heights
Now the white dialog box will become equal height to the green screen but don't worry. Select that height constraint and set the
multiplier to let's say 0.5 for 50% height of super view. Repeat the
same for width
Remove the height constraint and hook the bottom most button to the bottom of the view

Unable to center/properly scale button and label in view using constraints?

Im having a frustrating problem as I've worked with constraints in the past and have simply used the "Add missing constraints" to do the job, however I am having a LOT of difficulty achieving something very simple -
I have a larger button and a label positioned on my xib file. I need both these centered horizontally and scale with the device, and more or less maintain the distance between each other. Basically just need them to look reasonably good and for the button (which has an image within it) to scale but maintain aspect ratio.
Add missing constraints has not worked in the least as this results in neither the button nor label scaling (both stay small) and the space between them being too big on larger screens. I've tried every other constraint configuration but the button just ends up being squished or going off the screen. Here is what I'm trying to achieve:
The troublemaker is the button. Is there a way to do this programmatically? I am desperate here. How can I configure the constraints?
How do you set a distance between 2 objects?
Center the button horizontally and vertically with the view. Center the label to the view and give vertical spacing from button to the label. Also give width constraint to label if necessary. This will give you the desired effect.
For UIButton:
1.Centre Horizontally & centre vertically
2.Give Aspect ration (or) use leading,trailing,top,button for scale it to different device.
For UILabel
1.Centre it horizontally.
2.Set vertical to the UIButton.
2.Set Aspect ratio.
Hope this helps you.

Center label after dynamic text update in Axure

I've got a label we'll call selectedTextLabel with multiple labels underneath it forming a list (yes, I know about repeaters), when I select one of the lower labels I throw in that label's text description into selectTextLabel. The problem I've running into is that, though selectedTextLabel is aligned center (positionally) and the text within it is center aligned, when new text that is longer or shorter than the original gets put within it from an action, it keeps the same top left xy coordinants and increases or decreases the width accordingly making my design look misaligned.
It's almost like it's not obeying text-align: center on dynamic text like it does in the editor.
Does anyone know a solution? Is this a bug? I've googled but only have gotten editor based answers as opposed to dynamic browser based answers.
Thanks.
After an insight, it turns out it's rather easy. You just have to make the label the full width that you want it to be centered within. Then if you have text align center set, it'll keep the text centered.
What was happening in my instance was that I only had the label set to the width of the first selection and since the label didn't know what to do when something longer was set as the text, it expanded it's width but kept the same top left x and y coordinants, making the new center misaligned.
I hope this helps someone out there.

Why is not Edittext in Android vertically centered relative to its outside box?

Say, a default EditText is created. It has a default padding around the white editbox.
The default padding at the bottom is larger than the padding on the top.
This means: the center horizontal line of the EditText is not at the center of the white editbox.
If I put a imageView, Align Right and Center Vertical with the EditText, the imageview is not at the center of the white editbox.
I could manually nudge it. But I am afraid it will not apply to all devices.
A better solution?
Thanks!
I would suggest you follow this tutorial, this will achieve what you want and look great at the same time. http://www.wapolabs.com/2012/10/17/android-tip-1-customizing-an-edittext-view/
It is not good practice to put an anything in an edit text but text. Stick with customizing the edit text view as its not hard and keeps good functionality.
and as always set the padding when you customize an edit text to force the text to the exact spot you want it. padding will look fine on all phones.

Resources