Task 1: First task was a light lamp app in which we have to insert 2 images of bulb one in on state and other one in off state and by clicking the button the image changes from off to on state and we also kept track of number of clicks by the user.
Implementation:
I added 2 images of bulb on and bulb off in assets.xcassets folder.
I added a button from utilities area and dragging it into the screen and resizing it to the same as the size of the screen.
Then I assigned the lightoff image to the button.
Then I added the Action Handler to assign what button does and added the label to count the clicks by the user.
Then to change the image on the button click i used “setImage” function.
After that I used If-Else statement to satisfy 2 conditions of lightoff and lighton when the button is pressed.
Runtime images:
Reflection:
What I learned:
· How to insert images into the XCode.
· How to add button and label in the View Controller.
· How to assign the action with the help of “Action Handler”
· How to assign tags to different images and shift them using if-else statement.
TASK 2:
To create a calculator
which can perform addition, subtraction, multiplication and division and showing the result and keeping the track of all the calculations.
Implementation:
I added two labels for result and history to show the result by passing the reference and history of the calculations.
created a function for addition in which i created a variable for values of type double in which we pre-defined values were passed by reference and on those 2 values the addition takes place.
created same function with two variables x and y for subtraction.
created a function for multiplication and division in which i created a variable for values of type double in which we pre-defined values were passed by reference and on those 2 values multiplication and division takes place.
Runtime Images:
Reflection:
- learned how to use If-else statement
- learned how to use switch statement
- How to add button and label in the View Controller.
- How to assign the action with the help of “Action Handler”