Welcome,
Guest
. Please
login
or
register
.
June 13, 2026, 12:05:12 AM
Home
Help
Search
Login
Register
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
Line Width = Screen width?
« previous
next »
Print
Pages: [
1
]
Author
Topic: Line Width = Screen width? (Read 2791 times)
nübi
Guest
Line Width = Screen width?
«
on:
April 04, 2013, 04:08:41 PM »
How would I get a UILabel's Line Width to equal to the screen width?
Clearly a little script but is there a shortcut? Like auto-stretch or fill or something similar?
Thanks
Logged
nübi
Guest
Re: Line Width = Screen width?
«
Reply #1 on:
April 04, 2013, 09:44:37 PM »
OK so I assume there's no shortcut.
So I created that little script.
using
UnityEngine
;
using
System.Collections
;
public
class
LabelStretcher
:
MonoBehaviour
{
void
Start
(
)
{
UIRoot root
=
NGUITools
.
FindInParents
<
UIRoot
>
(
gameObject
)
;
float
scale
=
(
float
)
root
.
manualHeight
/
Screen
.
height
;
UIAnchor anchor
=
GetComponent
<
UIAnchor
>
(
)
;
float
offsetX
=
anchor
.
relativeOffset
.
x
;
float
widthPercentage
=
1f
-
offsetX
*
2f
;
// margin on left/right.
UILabel label
=
GetComponent
<
UILabel
>
(
)
;
label
.
lineWidth
=
(
int
)
(
scale
*
Screen
.
width
*
widthPercentage
)
;
}
}
Logged
Print
Pages: [
1
]
« previous
next »
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
Line Width = Screen width?