Here’s one way to horizontally center a UIToolkit object, such as a UIButton, using positionCenterX(). Should work pretty good on the various iPad sizes, iPhone 4, iPhone 5. The one thing to keep in mind is the scale of the actual graphic will need to be adjusted, either via UIToolkit’s UI.cs class that listens for HD, SD or supper HD screen sizes or manually via your own code.
Javascript version
#pragma strict public var buttonToolkit:UIToolkit; private var newGameBtn:UIButton; function Start() { newGameBtn = UIButton.create( buttonToolkit, "playBtnOff.png", "playBtnOn.png", 0, 0 ); newGameBtn.zIndex = 0; //centers it horizontally on iPad and iPhone: newGameBtn.positionCenterX(); //relatively positions it along y axis; slightly differnt actual position on iPads, iPhone 4, iPhone 5 newGameBtn.position.y = UIRelative.yPercentFrom( UIyAnchor.Bottom, 1.25f ); newGameBtn.highlightedTouchOffsets = new UIEdgeOffsets( 10 ); newGameBtn.onTouchUpInside += newGameBtnHandler; newGameBtn.alphaFrom( 1.0f, 0.0f, Easing.Quintic.easeOut ); } function newGameBtnHandler( sender:UIButton ) { Debug.Log("newGameBtn clicked!"); }
C# version
using UnityEngine; using System; using Prime31; public class ExampleManagerScript : MonoBehaviour { //set via Inspector panel public UIToolkit buttonToolkit; private UIButton newGameBtn; void Start() { newGameBtn = UIButton.create( buttonToolkit, "playBtnOff.png", "playBtnOn.png", 0, 0 ); newGameBtn.zIndex = 0; //centers it horizontally on iPad and iPhone: newGameBtn.positionCenterX(); //relatively positions it along y axis; slightly differnt actual position on iPads, iPhone 4, iPhone 5 newGameBtn.position.y = UIRelative.yPercentFrom( UIyAnchor.Bottom, 1.25f ); newGameBtn.highlightedTouchOffsets = new UIEdgeOffsets( 10 ); newGameBtn.onTouchUpInside += newGameBtnHandler; newGameBtn.alphaFrom( 1.0f, 0.0f, Easing.Quintic.easeOut ); } void newGameBtnHandler( UIButton sender ) { Debug.Log("newGameBtn clicked!"); } }