Skip to corpus content
HIMR Public Corpustimestamped source index

Recording

How to disable and enable a button in Xcode 7 macbook pro

2015-11-05 · 10 min

internet_archive
Machine transcript · wording, timing and speaker attribution may be wrong

Wording, speaker labels, and timestamps can still be wrong. A transcript does not establish that statements in the recording are factual. Use the source links and surrounding context.

Read summary

Expand to load the summary.

Open summary page ↗
Source information & transcript revisions

Transcript revisions

  1. rev_0038354098a56c23e06cfd9634389992Machine-generated and unreviewed; may be wrong; not a verified quotation.
    enraw_asractive150 segments

Transcript

en
  1. Hello and welcome to another Xcode

    Segment details0:00–0:03 · rev_0038354098a56c23e06cfd9634389992_0
  2. tutorial. So in this lesson, we'll be—

    Segment details0:04–0:06 · rev_0038354098a56c23e06cfd9634389992_1
  3. I'll be showing you how to make a button

    Segment details0:07–0:09 · rev_0038354098a56c23e06cfd9634389992_2
  4. and enable the button and disable the

    Segment details0:10–0:13 · rev_0038354098a56c23e06cfd9634389992_3
  5. button. So let's go ahead and create a new

    Segment details0:13–0:16 · rev_0038354098a56c23e06cfd9634389992_4
  6. project in Xcode by pressing File, then

    Segment details0:16–0:18 · rev_0038354098a56c23e06cfd9634389992_5
  7. New, and then Project, and then choose

    Segment details0:18–0:21 · rev_0038354098a56c23e06cfd9634389992_6
  8. Single View Application and just call it

    Segment details0:22–0:25 · rev_0038354098a56c23e06cfd9634389992_7
  9. whatever. I don't know, button. Whoops,

    Segment details0:25–0:28 · rev_0038354098a56c23e06cfd9634389992_8
  10. we're not typing in Chinese today. And

    Segment details0:28–0:31 · rev_0038354098a56c23e06cfd9634389992_9
  11. Objective-C. What else? Yeah,

    Segment details0:32–0:35 · rev_0038354098a56c23e06cfd9634389992_10
  12. just press Next and then Create.

    Segment details0:36–0:38 · rev_0038354098a56c23e06cfd9634389992_11
  13. Okay, so what do we have to do? First,

    Segment details0:41–0:45 · rev_0038354098a56c23e06cfd9634389992_12
  14. go to Main Storyboard, and this is our

    Segment details0:46–0:49 · rev_0038354098a56c23e06cfd9634389992_13
  15. ViewController. At the moment it's set

    Segment details0:50–0:53 · rev_0038354098a56c23e06cfd9634389992_14
  16. to this like funny size. I don't really

    Segment details0:54–0:55 · rev_0038354098a56c23e06cfd9634389992_15
  17. like it, so click on the top and what I

    Segment details0:56–0:58 · rev_0038354098a56c23e06cfd9634389992_16
  18. usually do is I disable Use Auto

    Segment details0:58–1:02 · rev_0038354098a56c23e06cfd9634389992_17
  19. Layout and disable Size Classes.

    Segment details1:02–1:04 · rev_0038354098a56c23e06cfd9634389992_18
  20. So now we have the iPhone size.

    Segment details1:07–1:08 · rev_0038354098a56c23e06cfd9634389992_19
  21. We also need to change this bit on Custom

    Segment details1:12–1:15 · rev_0038354098a56c23e06cfd9634389992_20
  22. Class. Oh no, not yet. Okay, first

    Segment details1:15–1:18 · rev_0038354098a56c23e06cfd9634389992_21
  23. right-click on your button and do New File

    Segment details1:18–1:21 · rev_0038354098a56c23e06cfd9634389992_22
  24. and do Cocoa Touch Class and just

    Segment details1:23–1:27 · rev_0038354098a56c23e06cfd9634389992_23
  25. leave it like this. You can name it— name

    Segment details1:28–1:31 · rev_0038354098a56c23e06cfd9634389992_24
  26. this bit to like Button or something,

    Segment details1:31–1:33 · rev_0038354098a56c23e06cfd9634389992_25
  27. it's up to you. And then

    Segment details1:33–1:36 · rev_0038354098a56c23e06cfd9634389992_26
  28. do Create, and then you'll see them

    Segment details1:36–1:40 · rev_0038354098a56c23e06cfd9634389992_27
  29. up here. You can move them down if you

    Segment details1:40–1:42 · rev_0038354098a56c23e06cfd9634389992_28
  30. want. But it's okay if you just leave

    Segment details1:43–1:44 · rev_0038354098a56c23e06cfd9634389992_29
  31. them. But I like to

    Segment details1:44–1:48 · rev_0038354098a56c23e06cfd9634389992_30
  32. move them down next to the main

    Segment details1:48–1:50 · rev_0038354098a56c23e06cfd9634389992_31
  33. storyboard. Now go to Custom Class on

    Segment details1:50–1:54 · rev_0038354098a56c23e06cfd9634389992_32
  34. the first view controller and change this

    Segment details1:54–1:57 · rev_0038354098a56c23e06cfd9634389992_33
  35. to Button. Okay,

    Segment details1:57–2:00 · rev_0038354098a56c23e06cfd9634389992_34
  36. so we're all set up.

    Segment details2:01–2:01 · rev_0038354098a56c23e06cfd9634389992_35
  37. Next we need is a button.

    Segment details2:10–2:11 · rev_0038354098a56c23e06cfd9634389992_36
  38. And what, what can we make the button do?

    Segment details2:13–2:15 · rev_0038354098a56c23e06cfd9634389992_37
  39. We can make the button make an image go

    Segment details2:17–2:19 · rev_0038354098a56c23e06cfd9634389992_38
  40. up. So first we need an image view. So

    Segment details2:19–2:22 · rev_0038354098a56c23e06cfd9634389992_39
  41. look for an image view in the bottom

    Segment details2:23–2:23 · rev_0038354098a56c23e06cfd9634389992_40
  42. right, drag it onto the screen. Now we

    Segment details2:24–2:28 · rev_0038354098a56c23e06cfd9634389992_41
  43. need an image. Okay, it doesn't

    Segment details2:28–2:32 · rev_0038354098a56c23e06cfd9634389992_42
  44. have to be an image view, we can do a

    Segment details2:32–2:33 · rev_0038354098a56c23e06cfd9634389992_43
  45. Whoops, label. Get rid of this.

    Segment details2:37–2:40 · rev_0038354098a56c23e06cfd9634389992_44
  46. Okay, so we'll make the label move up the

    Segment details2:42–2:43 · rev_0038354098a56c23e06cfd9634389992_45
  47. screen, and then we need a button.

    Segment details2:43–2:45 · rev_0038354098a56c23e06cfd9634389992_46
  48. There we go. And then just bring it down

    Segment details2:49–2:51 · rev_0038354098a56c23e06cfd9634389992_47
  49. here. We can name it to up.

    Segment details2:51–2:54 · rev_0038354098a56c23e06cfd9634389992_48
  50. Okay, first we have to declare, so go down

    Segment details2:56–3:00 · rev_0038354098a56c23e06cfd9634389992_49
  51. here, and then do open curly brackets and

    Segment details3:00–3:04 · rev_0038354098a56c23e06cfd9634389992_50
  52. close. And then we do IBOutlet UIButton,

    Segment details3:05–3:08 · rev_0038354098a56c23e06cfd9634389992_51
  53. and we'll just call it up. And we need

    Segment details3:10–3:12 · rev_0038354098a56c23e06cfd9634389992_52
  54. IBOutlet UILabel for our label.

    Segment details3:12–3:16 · rev_0038354098a56c23e06cfd9634389992_53
  55. We'll just call it label.

    Segment details3:16–3:17 · rev_0038354098a56c23e06cfd9634389992_54
  56. And then we need an IBAction. So that

    Segment details3:25–3:29 · rev_0038354098a56c23e06cfd9634389992_55
  57. when you press on the button, something

    Segment details3:29–3:30 · rev_0038354098a56c23e06cfd9634389992_56
  58. happens. And we'll call it Up— whoops,

    Segment details3:30–3:33 · rev_0038354098a56c23e06cfd9634389992_57
  59. no, just call it UpButton, and then

    Segment details3:38–3:41 · rev_0038354098a56c23e06cfd9634389992_58
  60. semicolon on the end. And then

    Segment details3:42–3:45 · rev_0038354098a56c23e06cfd9634389992_59
  61. we need to link it up. So go back to Main

    Segment details3:46–3:48 · rev_0038354098a56c23e06cfd9634389992_60
  62. Storyboard, click on the top, and then 6th

    Segment details3:49–3:51 · rev_0038354098a56c23e06cfd9634389992_61
  63. tab along Go to your label outlets and

    Segment details3:51–3:55 · rev_0038354098a56c23e06cfd9634389992_62
  64. then link it, and your button,

    Segment details3:56–3:58 · rev_0038354098a56c23e06cfd9634389992_63
  65. and your— where's the IBAction?

    Segment details4:02–4:04 · rev_0038354098a56c23e06cfd9634389992_64
  66. Oh, here it is, Received Actions, and then

    Segment details4:08–4:10 · rev_0038354098a56c23e06cfd9634389992_65
  67. on the button and do Touch Up Inside.

    Segment details4:10–4:12 · rev_0038354098a56c23e06cfd9634389992_66
  68. Okay, now we need to write the code. So

    Segment details4:18–4:19 · rev_0038354098a56c23e06cfd9634389992_67
  69. the button makes the label move.

    Segment details4:19–4:21 · rev_0038354098a56c23e06cfd9634389992_68
  70. So go into here, and under

    Segment details4:23–4:27 · rev_0038354098a56c23e06cfd9634389992_69
  71. implementation, I think we need a

    Segment details4:27–4:31 · rev_0038354098a56c23e06cfd9634389992_70
  72. semicolon here. Okay, so we go.

    Segment details4:31–4:34 · rev_0038354098a56c23e06cfd9634389992_71
  73. Let's do the label first.

    Segment details4:34–4:37 · rev_0038354098a56c23e06cfd9634389992_72
  74. So label, and we want the label to move

    Segment details4:38–4:42 · rev_0038354098a56c23e06cfd9634389992_73
  75. up every time we press the button. So do

    Segment details4:42–4:44 · rev_0038354098a56c23e06cfd9634389992_74
  76. label.center— was it label?

    Segment details4:45–4:48 · rev_0038354098a56c23e06cfd9634389992_75
  77. Yeah, label.center equals CGPoint.make

    Segment details4:51–4:55 · rev_0038354098a56c23e06cfd9634389992_76
  78. label.center— whoops— label.center.x,

    Segment details4:56–5:04 · rev_0038354098a56c23e06cfd9634389992_77
  79. label.center.y, and -25

    Segment details5:05–5:10 · rev_0038354098a56c23e06cfd9634389992_78
  80. to make it go up. And we

    Segment details5:10–5:14 · rev_0038354098a56c23e06cfd9634389992_79
  81. need brackets and then semicolon.

    Segment details5:14–5:17 · rev_0038354098a56c23e06cfd9634389992_80
  82. This is the wrong one. CGPoint make,

    Segment details5:19–5:21 · rev_0038354098a56c23e06cfd9634389992_81
  83. and then just get rid of all this.

    Segment details5:24–5:25 · rev_0038354098a56c23e06cfd9634389992_82
  84. Label.center CGPoint make. Make sure you

    Segment details5:31–5:34 · rev_0038354098a56c23e06cfd9634389992_83
  85. have the bracket there. Okay,

    Segment details5:35–5:38 · rev_0038354098a56c23e06cfd9634389992_84
  86. make sure you spell it right, so it's

    Segment details5:41–5:43 · rev_0038354098a56c23e06cfd9634389992_85
  87. capital L. Okay, so that's okay. Now we

    Segment details5:44–5:46 · rev_0038354098a56c23e06cfd9634389992_86
  88. need the button, so we do IBAction and

    Segment details5:47–5:49 · rev_0038354098a56c23e06cfd9634389992_87
  89. then upButton,

    Segment details5:50–5:51 · rev_0038354098a56c23e06cfd9634389992_88
  90. and then get rid of the semicolon, do open

    Segment details6:01–6:04 · rev_0038354098a56c23e06cfd9634389992_89
  91. curly brackets, close curly brackets.

    Segment details6:04–6:05 · rev_0038354098a56c23e06cfd9634389992_90
  92. Now I

    Segment details6:09–6:17 · rev_0038354098a56c23e06cfd9634389992_91
  93. got this wrong. You don't actually need

    Segment details6:17–6:19 · rev_0038354098a56c23e06cfd9634389992_92
  94. this void label, you need this bit inside

    Segment details6:19–6:21 · rev_0038354098a56c23e06cfd9634389992_93
  95. the button, and we can get rid of void

    Segment details6:22–6:23 · rev_0038354098a56c23e06cfd9634389992_94
  96. label. And when we do run,

    Segment details6:24–6:25 · rev_0038354098a56c23e06cfd9634389992_95
  97. press up and label goes up. Okay,

    Segment details6:30–6:33 · rev_0038354098a56c23e06cfd9634389992_96
  98. so that was easy. We only needed what this

    Segment details6:33–6:36 · rev_0038354098a56c23e06cfd9634389992_97
  99. IBAction. Okay, so now I'll show you how

    Segment details6:36–6:39 · rev_0038354098a56c23e06cfd9634389992_98
  100. to disable the button.

    Segment details6:39–6:40 · rev_0038354098a56c23e06cfd9634389992_99
  101. How should we do it? We could make a

    Segment details6:45–6:48 · rev_0038354098a56c23e06cfd9634389992_100
  102. second button to disable the first button.

    Segment details6:48–6:51 · rev_0038354098a56c23e06cfd9634389992_101
  103. Okay, so copy and paste the button. And we

    Segment details6:55–6:59 · rev_0038354098a56c23e06cfd9634389992_102
  104. can just call it disable,

    Segment details6:59–7:03 · rev_0038354098a56c23e06cfd9634389992_103
  105. disable button.

    Segment details7:05–7:06 · rev_0038354098a56c23e06cfd9634389992_104
  106. And then, or we can also have enable

    Segment details7:10–7:14 · rev_0038354098a56c23e06cfd9634389992_105
  107. button.

    Segment details7:14–7:14 · rev_0038354098a56c23e06cfd9634389992_106
  108. Then go into button.h and then

    Segment details7:21–7:24 · rev_0038354098a56c23e06cfd9634389992_107
  109. IBOutlet UIButton,

    Segment details7:25–7:26 · rev_0038354098a56c23e06cfd9634389992_108
  110. EnableButton, and just copy

    Segment details7:29–7:32 · rev_0038354098a56c23e06cfd9634389992_109
  111. this and paste it and change this to

    Segment details7:33–7:35 · rev_0038354098a56c23e06cfd9634389992_110
  112. Disable.

    Segment details7:35–7:35 · rev_0038354098a56c23e06cfd9634389992_111
  113. Okay, then we need 2 more IBActions,

    Segment details7:39–7:41 · rev_0038354098a56c23e06cfd9634389992_112
  114. EnableButton.

    Segment details7:46–7:46 · rev_0038354098a56c23e06cfd9634389992_113
  115. Disable button.

    Segment details7:55–7:56 · rev_0038354098a56c23e06cfd9634389992_114
  116. And now we have to link those up.

    Segment details8:00–8:01 · rev_0038354098a56c23e06cfd9634389992_115
  117. Where is it? Disable button.

    Segment details8:05–8:07 · rev_0038354098a56c23e06cfd9634389992_116
  118. Let's move them a bit further apart.

    Segment details8:07–8:11 · rev_0038354098a56c23e06cfd9634389992_117
  119. And enable button. And then

    Segment details8:13–8:16 · rev_0038354098a56c23e06cfd9634389992_118
  120. disable button received actions, touch up

    Segment details8:16–8:20 · rev_0038354098a56c23e06cfd9634389992_119
  121. inside.

    Segment details8:20–8:20 · rev_0038354098a56c23e06cfd9634389992_120
  122. Is that up? Get rid of these. I don't know

    Segment details8:25–8:28 · rev_0038354098a56c23e06cfd9634389992_121
  123. why it's done this.

    Segment details8:28–8:29 · rev_0038354098a56c23e06cfd9634389992_122
  124. This is up. And then enable button on the

    Segment details8:32–8:35 · rev_0038354098a56c23e06cfd9634389992_123
  125. enable button, touch up inside.

    Segment details8:35–8:37 · rev_0038354098a56c23e06cfd9634389992_124
  126. Okay, so So we need IBAction

    Segment details8:40–8:44 · rev_0038354098a56c23e06cfd9634389992_125
  127. here, disableButton,

    Segment details8:44–8:47 · rev_0038354098a56c23e06cfd9634389992_126
  128. and what we do is up— this

    Segment details8:52–8:56 · rev_0038354098a56c23e06cfd9634389992_127
  129. is the name of our up button.

    Segment details8:57–8:58 · rev_0038354098a56c23e06cfd9634389992_128
  130. We do up.enabled and

    Segment details9:07–9:12 · rev_0038354098a56c23e06cfd9634389992_129
  131. equals yes— no, equals no.

    Segment details9:12–9:14 · rev_0038354098a56c23e06cfd9634389992_130
  132. So that should stop the up button from

    Segment details9:16–9:18 · rev_0038354098a56c23e06cfd9634389992_131
  133. working. Let's test it out.

    Segment details9:18–9:19 · rev_0038354098a56c23e06cfd9634389992_132
  134. So it's working now. Disable, it's

    Segment details9:26–9:28 · rev_0038354098a56c23e06cfd9634389992_133
  135. disabled, so it doesn't work now. It's

    Segment details9:29–9:30 · rev_0038354098a56c23e06cfd9634389992_134
  136. grayed out. Okay, let's enable

    Segment details9:30–9:33 · rev_0038354098a56c23e06cfd9634389992_135
  137. it. IBAction,

    Segment details9:34–9:36 · rev_0038354098a56c23e06cfd9634389992_136
  138. you want EnableButton,

    Segment details9:37–9:38 · rev_0038354098a56c23e06cfd9634389992_137
  139. and then

    Segment details9:42–9:48 · rev_0038354098a56c23e06cfd9634389992_138
  140. we do up.enabled equals

    Segment details9:49–9:52 · rev_0038354098a56c23e06cfd9634389992_139
  141. yes.

    Segment details9:53–9:53 · rev_0038354098a56c23e06cfd9634389992_140
  142. So it's moving up. We disable the button,

    Segment details9:59–10:01 · rev_0038354098a56c23e06cfd9634389992_141
  143. it's not moving up anymore. Then we enable

    Segment details10:01–10:04 · rev_0038354098a56c23e06cfd9634389992_142
  144. the button, and now we can continue moving

    Segment details10:04–10:06 · rev_0038354098a56c23e06cfd9634389992_143
  145. up. So that was all for the tutorial.

    Segment details10:06–10:09 · rev_0038354098a56c23e06cfd9634389992_144
  146. It's quite simple really, but it actually

    Segment details10:09–10:12 · rev_0038354098a56c23e06cfd9634389992_145
  147. took me a long time to figure it out. So

    Segment details10:13–10:15 · rev_0038354098a56c23e06cfd9634389992_146
  148. hopefully you can use this for something

    Segment details10:16–10:18 · rev_0038354098a56c23e06cfd9634389992_147
  149. in your app, and I'll see you next

    Segment details10:18–10:22 · rev_0038354098a56c23e06cfd9634389992_148
  150. time. Thanks for watching!

    Segment details10:22–10:24 · rev_0038354098a56c23e06cfd9634389992_149