Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Neodim · Aug 23, 2012 at 11:14 AM · guitextfieldguistyle

Single-line GUI.TextField with custom GUIStyle

I meet some troubles when I try to make input field with custom style on iOS. I need a keyboard without any additional fields, only buttons. When I make

 TouchScreenKeyboard.hideInput = true;

it works perfectly, but when I try to use my GUIStyle for customize font and background of input field, it becomes a multiline, and hideInput becomes useless.

There are example of my code:

 GUIStyle myCustomStyle = new GUIStyle();
 myCustomStyle.font = Resources.Load("myfont") as Font;
 myCustomStyle.normal.textColor = Color.blue;
 GUI.TextField(new Rect(0,0,200,50), "hello world!", myCustomStyle);

As a result, I get a multi-line input field (but if I call GUI.TextField without specified GUIStyle, it is single-line), and hideInput does not have any effect with this field.

How can I make single-line GUI.TextField with custom GUIStyle?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Sundar · Aug 23, 2012 at 04:17 PM

Check font size, is it same as default font, if not make it same. Also, you can set your GUIStyle wordWrap to false and clipping set to clip like

 myCustomStyle.wordWrap = false;
 myCustomStyle.clipping = TextClipping.clip;
Comment
Add comment · Show 5 · 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 Neodim · Aug 23, 2012 at 04:38 PM 0
Share

Unfortunately, it didnt works. When I pass any style to TextField, it becomes multi-line. Even if I do

 GUIStyle myStyle = new GUIStyle(GUI.skin.textField);
 someString = GUI.TextField(someRect, someString, myStyle);

it results with multi-line textfield, but

 someString = GUI.TextField(someRect, someString);

give me single-line textfield.

avatar image Sundar · Aug 23, 2012 at 07:00 PM 0
Share

Can you check Debug.Log(myCustomStyle.imagePosition );

if it is not "TextOnly", then assign myCustomStyle.imagePosition = TextOnly;

avatar image Neodim · Aug 24, 2012 at 11:31 AM 0
Share

I check imagePosition and it is TextOnly. But when I digging around, I found out what I was stupid. Problem appears not when I specify style, but when i specify max length and style. I.e. code like

 someString = GUI.TextField(someRect, someString, 40);

or

 someString = GUI.TextField(someRect, someString, myStyle);

works perfectly, like simple

 someString = GUI.TextField(someRect, someString);

but I get multi-line text field when I make

 someString = GUI.TextField(someRect, someString, 40, myStyle);

Sorry for misleading you in my previous posts.

avatar image Sundar · Aug 24, 2012 at 03:25 PM 0
Share

No problem, it happens to all the best people.

avatar image caroparo · Nov 20, 2012 at 07:10 AM 0
Share

Just curious: am I the only one getting a single-line TextArea?

avatar image
0

Answer by Neodim · Aug 24, 2012 at 01:37 PM

I check imagePosition and it is TextOnly. But when I digging around, I found out what I was stupid. Problem appears not when I specify style, but when i specify max length and style. I.e. code like

 someString = GUI.TextField(someRect, someString, 40);

or

 someString = GUI.TextField(someRect, someString, myStyle);

works perfectly, like simple

 someString = GUI.TextField(someRect, someString);

but I get multi-line text field when I make

 someString = GUI.TextField(someRect, someString, 40, myStyle);

Sorry for misleading you in my previous posts.

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
0

Answer by naii · Sep 15, 2014 at 12:19 PM

Found this old topic while searching for something else, in case someone would be interested in this though... maybe it would be worth trying GUI.skin.textField

 GUIStyle myStyle = new GUIStyle(GUI.skin.textField);
 someString = GUI.TextField(someRect, someString, 40, myStyle);
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

10 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

Related Questions

Background of GUI.TextField disappears when using a GUIStyle 2 Answers

GUI custom textfield cursor rendering 2 Answers

Understanding GUISkin/GUIStyle BackgroundImage and Border 2 Answers

Problem with Android Keyboard/TextField 1 Answer

Access custom style from skin via string 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