Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jeango · Dec 07, 2015 at 06:23 PM · uifont size

how to normalize font size across multiple UI text field using "best fit" and "max size"

Hi, I'm using "best fit" to display text in my UI buttons.

I first tried to set Max Size to something that looked good on desktop, but when I deployed my game on iPad with its retina display, the max size was way too small. So I figured I'd use a big value for max size (was 20, set it to 80) but it results in some buttons having bigger font size than others according to the amount of text in each button.

So what's the good way to deal with this? Should I forget "best fit" and hardcode font sizes according to resolution and taking into account retina display? Or is there a way to normalize the font size across all buttons.alt text

screen-shot-2015-12-07-at-192242.png (119.3 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by RowanG1 · Mar 02, 2018 at 01:41 AM

The way that has worked the best for me:

 bool hasSetAllFontSizeSameSinceLastRefresh;
 
 Update() {
     if (hasSetAllFontSizeSameSinceLastRefresh == false)
         {
             SetAllFontSizesSame();
         }
  if (someConditionToUpdateTextMet) {
 updateYourTextElement();
 hasSetAllFontSizeSameSinceLastRefresh == false;
 }
 }

 void SetAllFontSizesSame() {
 List<int> allTextItemsFontSize = new List<>();
 foreach (GameObject textItem in allYourTextGameObjectsArray) {
  eachTextItemFontSize = textItem.GetComponent().cachedTextGenerator.fontSizeUsedForBestFit;
 allTextItemsFontSize.Add(eachTextItemFontSize);
 }
 smallestFontSize  = allTextItemsFontSize.Min();
  float multiplier = 1 / canvas.scaleFactor;
 eachTextComponent.GetComponent().resizeTextMaxSize = (int)Mathf.Floor(smallestFontSize * multiplier);
 hasSetAllFontSizeSameSinceLastRefresh == true;
 }

When updateYourTextElement() is run, we leave the max font size for best fit to be quite large. Or for optimal continuity, set the value a bit higher than the last smallest font size. Otherwise, you might experience "jumping" from a large font size to a small font size.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

40 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is there a way to find the current font size of a Text? 2 Answers

When game resolution is 4k, UI text font size stops scaling from 145 0 Answers

How can I set the UI Text font size higher than 300px ? | Unity 5.4 2 Answers

UI Position Correction for worldspace UI? 1 Answer

Does Unity 5.6 free/pro provide support to open external applications inside the Unity scene? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges