Use the layout guides to help with positioning. From the Library, drag a Button onto the layout, below the Tax Percentage and centered. In the Inspector, change the name to TaxSlider, set the Maximum Value to 10 and Value to 6.īutton. Use the layout guides to position it properly and resize it to the right margin. From the Library, drag a Slider onto the layout, to the right of the Tax Percentage layout. In the Inspector, change the name to BillTotalField, the InputType to Decimal, and remove the default Text. ![]() From the Library, drag a TextField onto the layout, to the right of the Bill Total label. You'll also want to set the name of this second label (in the Inspector) to TaxPctLabel so that it can be easily referred to in the code later. With it selected, press RETURN to set its text to Bill Total (Post-Tax).ĭo the same thing for a second label (position it below the first, with the same width) and set its text to Tax Percentage (0%). From the Library (click the Library button on the toolbar to show it if necessary), drag a Label control onto the Screen.ĭrag the Label to the top left of the Screen and use the layout guides that appear to help you position it with appropriate margins.ĭrag it so that its width is about half of the layout. ![]() In the Inspector for TipCalculatorScreen, set the Title text to Tip Calculator. Click it in the Navigator and change its name to something better: TipCalculatorScreen. The default screen is given the name Screen1. Like with the Swift tutorial, you'll go through it one step at a time: And you'll also want a Navigation Bar to show the app's name, a button to do the tip calculation and a Text Area to show the results. In addition to those two controls, you'll want a couple labels (for the Text Field and Slider). As with the Swift tutorial, a Text Field is perfect for entering the bill amount and a Slider works well for the tax amount. In the case of the Tip Calculator, there are two inputs fields on the view: the total bill amount and the tax rate. In Xojo, mobile layouts are called Screens. This computed property will calculate the subtotal each time based on the Total and TaxPct properties.Įxpand the Subtotal computed property (in the Navigator) and In the Get section of Subtotal, put this code: Instead it is computed each time based on other values. Like with Swift, a computed property does not actually store a value. Again, click the Insert button on the toolbar and choose Computed Property to add it to the class. ![]() Now add a second property, TaxPct As Double to the class in the same manner. You can just type Total As Double for the name to have the type set automatically. Name it Total and set its type to Double. Now click the Insert button on the toolbar and choose Property to add a property to the class. To match the Swift code, you'll add the same properties and methods. Xojo uses an event-driven programming model that is much easier to work with (although you can also use MVC if you want).Įven though this simple app does not really need a separate class to do the actual tip calculation, you will make one to keep the steps aligning closely with the original Swift tutorial.Ĭlick the Insert button on the toolbar and choose Class to add a new class to your project.Ĭhange its name to TipCalculator using the Inspector on the right. This is a useful pattern, but it can be overkill for simple apps and can be a bit tricky to grasp for those unfamiliar with it. Swift, Xcode and Cocoa generally want you to use the Model-View-Controller design pattern. ![]() Reporting bugs and making feature requests.Building a tip calculator to compare Xojo and Swift.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |