Skip to main content

IOS / Touch and UI Study - Buttons

Just recently, I am starting to dig into XCode and iOS app development with Swift language.

For me, as beginner, my curiosity really revolves around Touch interface and how I can actually use it for things like the ARKit, maybe it will involve the SceneKit and SpriteKit.

I am probably going to try the generic and premade UI that is provided with XCode and iOS API. The version of XCode I am using is either 8 or 9 Beta.

SOURCE OF STUDY

I am self taught with Swift and programming. So far, I am reading Apple's provided iOS development and Swift programming iBooks. There are some resources online dated from 2014, some are using older Swift and XCode. It is a good idea I think to invest on full course or proper books on iOS development, this way, you have some kind of hollistic approach, a guide of some sort from start to the end. Although you can always randomly crawling for interesting topics.

I guess the most important step is to get used to XCode environment and Swift coding. Do not worry, it is not actually as intimidating. Think of it this way: Apple iOS development using XCode is truly one of the easiest out there.

Let's just jump into it.

USING BUTTON UI

From the menu, select File - New Project.

We can start with Single View App and make simple buttons.


Starting from a template, you will get a bunch of starting files. Most noticeably the LaunchScreen.storyboard, Main.storyboard and ViewController.swift.




And bunch of Swift code already prepared for you.

From the Main.storyboard view, we can start adding Buttons object(s). This is actually pretty cool and exciting experience for me.

Glad we do not actually need to code to place an object into the layout. We simply find it from the Object Library panel.

Things are pretty intuitive, even for total beginner. It might be slightly a surprise that we already have few parts for the app we are making:
- SCRIPT (Swift)
- STORYBOARD (Layout of Objects)
- OBJECTS (with Parameters)

We need to connect all of those together, dragging Objects into STORYBOARD is the first most logical step. Next is to provide linking.

Let say that we would like to make the BUTTON to change the UIView Background Color.

By searching around the web and finding online tutorial on YouTube, I figure we need to make OUTLET from OBJECT. This can be accomplised in few different ways. You either CTRL click drag from Button Object into the Script (ViewController class), or you drag the connection from the Properties of Object.

Give a unique variable name per button.



Hovering over the DOTS will highlight the button object.


Next thing we need to do is to add the actual ACTION. This ACTION can be triggered based on EVENT, and for each Object like BUTTON, we need to find the right event that we like to link with certain action.

So far I found it still quite strange that we need to do this HOOKING and LINKING visually, but probably this will become a second nature. I might be wrong, but we cannot just simply write down Script without actually linking and hooking the OUTLET.

Correct Linking of Outlet and Action highlighted:


Sometimes we might found ACTION and SCRIPT that is not yet linked to the OUTLET. Or it might be connected to the wrong object. That is something that we always need to watch for. To fix it, we just need to click and drag from OUTLET to correct OBJECT or TARGET, and also FUNCTION. They are all separate and sometimes need to be linked.

For the function we are using, we simply wanted to change the VIEW Background Color and somewhat the one I found is:
view.backgroundColor = UIColor.red
view.backgroundColor = UIColor.green
view.backgroundColor = UIColor.blue
view.backgroundColor = UIColor.white

It appears from dropdown recommendation by luck.

So that is pretty much it for this Button UI example. I can summarize:
- Drop some UI Button into Storyboard Layout
- Link Outlet of Button and assign Function that trigger based on user event
- Test the app

FEW TIPS

1.
Very often you wanted to fit Contents to Object, such as if we want to resize the Button object to fit the Text we assigned, shortcut is CMD + Equal Symbol


By using "Size to Fit" content function, we can quickly fix such issue above.


2.
Option + Click on ANYTHING in XCode, can often give us some ideas about certain Script or Object or anything basically. Things like documentation, how object is being declared, etc.


3.
XCode is a very friendly environment for building an app. You basically cannot go wrong and it will always try to help you to fix any bug. Swift programming is also especially fun and interactive. If you are not confident with app development, you can always play around inside Swify Playground first.

The only most difficult error is when the app crashes because of memory error, but you can always ask at the Apple Developer Forum, many will try to answer your questions. Sometimes Stack Exchange (online forum) is also good, normally you can get answer by Google Searching.

4.
Test your app often, whether using actual iOS mobile device like iPhone or iPad (connected via USB cable), or using the Simulator, I think it is a good idea to always test the code.


Hopefully this article can be somewhat helpful for beginners. I am only using BUTTON object, but there are few other basics OBJECT you can easily drop into the storyboard to quickly create an actual simple app:

  • SLIDERS
  • IMAGE VIEW
  • LABEL
  • SWITCH

For me the most accomplishment is to see the app running on the actual device right away.

Comments

Popular posts from this blog

PYTHON / OpenCV, Recreate Uncanny Manga - Anime Style

Can you tell what it is? Computer Vision. Yesterday, I spend almost whole day exploring this opencv module using Python. What I discovered was revealing. Even at the very basic level, I could produce some interesting Image and Video manipulation using all the code collected from documentation and many, many blog tutorials. If you are a total noob like me, I am still getting used to knowing that the CV in OpenCV means Computer Vision! Actuallly, I recalled that I did try to get into OpenCV few years back ago, when I knew no Python and when Python opencv module was probably still early. It was all C++ code and it was a little bit too hard for me. I read a couple of books about opencv at the library, I did not understand a single thing. That was back then. Today, for strange reason, with a bit of knowledge of Python, I can go a little further. EDGE DETECT IN OPENCV Me holding you know what. What leads me this far is my curiosity on how we can replicate Wolfram Langu

PYTHON PROCESSING / It only really begins ...

Back into Processing again, with Python! While Daniel Shiffman is continuously inspiring us with his CODING TRAIN series on YouTube, using Processing with Java and Javascript language, I decided to free my mind and trying to really do something using Processing and Python language. Installing Python language version on Processing 3 is easy enough, just first download the latest Processing and install the Python language mode via Add Mode button. Other link that might help: https://github.com/jdf/processing.py http://py.processing.org/tutorials/ BLANK MODE As soon as Processing Python Mode, opens up and running I am presented with a  blank environment. Suddenly I recalled my journey in learning programming from zero until now... With Python, outside Processing, commonly people will be introduced to Python IDE or IDLE environment. Something that looks like Console Window or Command Prompt, where we type single liners command. Python Command Line and IDE normally have t

WOLFRAM / Making Text With Rainbow Color

Continuing with my Wolfram Mathematica Trial Experience... I watched and went through some more Mathematica introduction videos, read lots of Mathematica documentation and also going through the Wolfram Lab Online again a few times. There are some major learning curves and Mathematica is a lot different from normal programming language. Sometimes there is a lot of interesting "shortcuts", say like: FindFaces[] , WordCloud[] . Sometimes I got a little confused on how one can do iterations. Normally FOR LOOP concept is introduced early, but in Wolfram, because everything is EXPRESSIONS and ENTITY (like OBJECTS), sometimes it gets quite quirky. Mind you I am still in the first impression and having to look at many tutorials. Lots of NEAT EXAMPLES from documentation, but sometimes I got lost. I found Wolfram to be really awesome with LIST and generating list. It's almost too easy when it works visually. I cannot explain them with my own words yet, but there are