Guest User

Untitled

a guest
Jun 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. var win = Titanium.UI.currentWindow;
  2.  
  3. var b1 = Titanium.UI.createButton({
  4. title:'I am a Button',
  5. height:40,
  6. width:200,
  7. top:10
  8. });
  9.  
  10.  
  11. var b2 = Titanium.UI.createButton({
  12. title:'I am a Button',
  13. image:'../images/chat.png',
  14. width:200,
  15. height:40,
  16. top:60
  17. });
  18.  
  19.  
  20. var b3 = Titanium.UI.createButton({
  21. backgroundImage:'../images/BUTT_grn_off.png',
  22. backgroundSelectedImage:'../images/BUTT_grn_on.png',
  23. backgroundDisabledImage: '../images/BUTT_drk_off.png',
  24. color:'#fff',
  25. top:60,
  26. height:100,
  27. width:100
  28. });
  29.  
  30. var buttonLabel = Titanium.UI.createLabel({
  31. color:'#f00',
  32. font:{fontSize:20,fontWeight:'bold',fontFamily:'Helvetica Neue'},
  33. highlightedColor:'#0f0',
  34. text:'Custom Label',
  35. textAlign:'center',
  36. touchEnabled:false,
  37. top:b3.top,
  38. height:b3.height,
  39. width:b3.width
  40. });
  41. win.add(b3);
  42. win.add(buttonLabel);
  43.  
  44. var state = 0;
  45. b3.addEventListener('click', function(e){
  46. switch (state)
  47. {
  48. case 0:
  49. {
  50. e.source.enabled=false;
  51. buttonLabel.text = 'I am Disabled';
  52. state++;
  53.  
  54. setTimeout(function(){
  55. e.source.enabled=true;
  56. buttonLabel.text = 'I am Enabled';
  57. },3000);
  58. break;
  59. }
  60. case 1:
  61. {
  62. buttonLabel.font = {fontSize:22,fontFamily:'Marker Felt', fontWeight:'bold'};
  63. buttonLabel.title = 'I am red';
  64. e.source.backgroundImage = '../images/BUTT_red_off.png';
  65. e.source.backgroundSelectedImage = '../images/BUTT_red_on.png';
  66. buttonLabel.color = '#222';
  67. state++;
  68. break;
  69. }
  70. case 2:
  71. {
  72. buttonLabel.color = '#fff';
  73. buttonLabel.text = 'White text';
  74. state=0;
  75. break;
  76. }
  77. }
  78. });
  79.  
  80. var b4 = Titanium.UI.createButton({
  81. title:'Hide/Show Button Above',
  82. width:200,
  83. height:40,
  84. top:175
  85. });
  86.  
  87. var visible = true;
  88. b4.addEventListener('click', function()
  89. {
  90. if (!visible)
  91. {
  92. b3.show();
  93. visible=true;
  94. }
  95. else
  96. {
  97. b3.hide();
  98. visible=false;
  99. }
  100. });
  101.  
  102. var b5 = Titanium.UI.createButton({
  103. width:200,
  104. height:40,
  105. top:225
  106. });
  107. var b5Label = Ti.UI.createLabel({
  108. text:'Label',
  109. width:50,
  110. height:20,
  111. color:'#336699'
  112. });
  113. b5.add(b5Label);
  114.  
  115. var b5ImageView = Ti.UI.createImageView({
  116. url:'../images/camera.png',
  117. left:10,
  118. height:33,
  119. width:33
  120. });
  121. b5.add(b5ImageView);
  122. b5.addEventListener('touchstart', function()
  123. {
  124. b5Label.color = 'red';
  125. });
  126. b5.addEventListener('touchend', function()
  127. {
  128. b5Label.color = '#336699';
  129. });
  130. win.add(b1);
  131.  
  132. win.add(b4);
  133.  
  134. // add iphone specific tests
  135. if (Titanium.Platform.name == 'iPhone OS')
  136. {
  137. win.add(b2);
  138. win.add(b5);
  139. }
  140.  
  141. var bhleft = Titanium.UI.createButton({
  142. title : 'H-Left',
  143. width : 50,
  144. height: 40,
  145. top : 300,
  146. left : 60
  147. });
  148. bhleft.addEventListener('click', function() {
  149. b1.textAlign = Titanium.UI.TEXT_ALIGNMENT_LEFT;
  150. });
  151.  
  152. var bhcenter = Titanium.UI.createButton({
  153. title : 'H-Center',
  154. width : 50,
  155. height: 40,
  156. top : 300,
  157. left : 120
  158. });
  159. bhcenter.addEventListener('click', function() {
  160. b1.textAlign = Titanium.UI.TEXT_ALIGNMENT_CENTER;
  161. });
  162.  
  163. var bhright = Titanium.UI.createButton({
  164. title : 'H-Right',
  165. width : 50,
  166. height: 40,
  167. top : 300,
  168. left : 180
  169. });
  170. bhright.addEventListener('click', function() {
  171. b1.textAlign = Titanium.UI.TEXT_ALIGNMENT_RIGHT;
  172. });
  173.  
  174. var bvtop = Titanium.UI.createButton({
  175. title : 'V-Top',
  176. width : 50,
  177. height: 40,
  178. top : 350,
  179. left : 60
  180. });
  181. bvtop.addEventListener('click', function() {
  182. b1.verticalAlign = Titanium.UI.TEXT_VERTICAL_ALIGNMENT_TOP;
  183. });
  184.  
  185. var bvcenter = Titanium.UI.createButton({
  186. title : 'V-Center',
  187. width : 50,
  188. height: 40,
  189. top : 350,
  190. left : 120
  191. });
  192. bvcenter.addEventListener('click', function() {
  193. b1.verticalAlign = Titanium.UI.TEXT_VERTICAL_ALIGNMENT_CENTER;
  194. });
  195.  
  196. var bvbottom = Titanium.UI.createButton({
  197. title : 'V-Bottom',
  198. width : 50,
  199. height: 40,
  200. top : 350,
  201. left : 180
  202. });
  203. bvbottom.addEventListener('click', function() {
  204. b1.verticalAlign = Titanium.UI.TEXT_VERTICAL_ALIGNMENT_BOTTOM;
  205. });
  206.  
  207. win.add(bhleft);
  208. win.add(bhcenter);
  209. win.add(bhright);
  210. win.add(bvtop);
  211. win.add(bvcenter);
  212. win.add(bvbottom);
Add Comment
Please, Sign In to add comment