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
3
Question by deltron1830 · Mar 23, 2016 at 11:54 PM · uitextlayoutpanel

How to make UI Panel scale to fit content

Im trying to learn the new UI system.

Heres a simple panel with text as its child (note, the pointer on the topleft is just an image and is not relevent) alt text

I'd like the panel to resize based on the text within in it something like this.

alt text

Ive tried adding a layout element to the text and a horizontal layout group and content size fitter to the panel (and a bunch of other combinations) but I always get really weird behaviour (for example the panel growing exponentially bigger than the text).

I'm on the cusp of just getting getting the behaviour I want through code, but I want to give the new UI system a go.

tapthis.png (29.4 kB)
tapthis2.png (46.0 kB)
Comment
Add comment · Show 2
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 Fredex8 · Mar 25, 2016 at 03:31 AM 0
Share

This is a pretty good explanation of how to do it. I didn't find the Unity documentation especially helpful on this subject.

avatar image deltron1830 Fredex8 · Mar 25, 2016 at 06:43 PM 0
Share

...Thanks!

2 Replies

· Add your reply
  • Sort: 
avatar image
7
Best Answer

Answer by deltron1830 · Mar 26, 2016 at 05:17 PM

So you need to put a content size fitter and also a layout group (horizontal or vertical, doesnt matter as there is only one child) on the Panel.

But a really important thing that I missed is that you must correctly set the pivot and anchor of the panel and text before you add those components. Any changes you try to make to them after adding those components will be ignored and their positions definitely affects how the text will expand. Also if your text is scaled you will get weird behaviour (ie. the panel growing exponentially bigger than the text)

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
avatar image
3

Answer by Happy-Zomby · Mar 25, 2016 at 07:09 PM

Hi, did you have a look here? http://docs.unity3d.com/Manual/HOWTO-UIFitContentSize.html

I guess you could make the image a child of the text - and then put a "size fitter" component on that text box.

hope that helps,

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

56 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 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

Using iTween with the new Unity UI 2 Answers

Fill empty space in parent in UI Layout 1 Answer

Cannot get text+image always centered 1 Answer

UI: Creating UI based on many strings 0 Answers

Make UI always center the panel 1 Answer


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