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
1
Question by siddharth3322 · Sep 21, 2015 at 03:10 PM · uitextunity 4.6

Based on text content increase container size

For my game, I am using new Unity UI. I have question regarding this.

I want to increase my container size based on more number of characters enter into text area. So based on text, I want to increase container size. Following image represent my question clearly.

alt text

Please give me your suggestion.

screen-shot-2015-09-21-at-83754-pm.png (81.5 kB)
Comment
Add comment · Show 3
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
avatar image Nerevar · Sep 21, 2015 at 03:21 PM 0
Share

Hello,

Have you tried the content size fitter?

avatar image siddharth3322 Nerevar · Sep 21, 2015 at 03:21 PM 0
Share

I have tried with content size fitter but cant able to increase size of container.

avatar image Nerevar siddharth3322 · Sep 22, 2015 at 07:30 AM 0
Share

Ah yes you actually need a vertical or horizontal layout on the parent container AND a content size fitter as specified here("Fit to size of UI element with child Text" section).

You can then use the padding parameters of the to adjust the margins around your text.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by amanpu · Sep 22, 2015 at 11:11 AM

You should use Content Size Filter along with Horizontal Layout Group. For this follows the following steps:

  • Add Canvas -> Image (Container of your text)

  • Add Text and make it child of Image

  • Add Content Size Filter and Horizontal Layout Group components to Image

  • Select preferred size in both Horizontal fit and Vertical fit fields in Content Size Filter
    alt text


Hope this helps


screen-shot-2015-09-22-at-43710-pm.png (29.5 kB)
Comment
Add comment · Show 4 · 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
avatar image Baste · Sep 22, 2015 at 11:44 AM 0
Share

If you want more fine-grained controll than a Content Size Fitter, you can ask the text for it's preferred width and height with the preferredWidth and preferredHeight properties.

avatar image amanpu Baste · Sep 22, 2015 at 11:53 AM 0
Share

@Baste I couldn't find preferredWidth and preferredHeight properties, Can you help more?

avatar image amanpu Baste · Sep 22, 2015 at 12:02 PM 0
Share

Ok I found them, but how to make use of them as they are read only

avatar image Baste amanpu · Sep 22, 2015 at 12:26 PM 0
Share

You don't want to set them - you want to read them and then resize whatever container you're using to fit the text.

Say you want to have a lot wider margins than what the Content Size Fitter gives you. Then you could reference the preferredWidth of your text object, and set the container to have that width pluss your custom margins.

You could probably fix that by adding invisible panels on both sides of the text - this is just a different way of doing the same thing.

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

34 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

Related Questions

How to render html text in new UI system (unity 4.6) 0 Answers

How To Change Color Of Text On UI When It's Selected | Unity 4.6 3 Answers

Unity 4.6 Text Misbehaves During Gameplay 1 Answer

Text with glow effect 7 Answers

I'm trying to display my ammo; not working 2 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