archive-com.com » COM » T » TECHOTOPIA.COM

Total: 1018

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • Understanding the iOS 8 Auto Layout Visual Format Language in Swift - Techotopia
    two view objects is represented by a hyphen mybutton1 mybutton2 The above example instructs the Auto Layout system to create a constraint using the standard spacing for views The following construct on the other hand specifies a spacing distance of 30 points between the two views mybutton1 30 mybutton2 By default constraints of the type outlined above are assumed to be horizontal constraints Vertical constraints are declared using a V prefix For example the following syntax establishes a vertical spacing constraint between two views V mylabel 50 mybutton For consistency and completeness horizontal constraints may optionally be prefixed with H eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters The width of a view can be set specifically as follows mybutton 100 Alternatively inequality can be used mybutton 100 Using similar syntax the width of one view can be constrained to match that of a second view mylabel mybutton2 When using the visual format language the superview of the view for which the constraint is being described is represented by the character For example the following visual format language construct declares a constraint for the mybutton1 view that attaches the leading and trailing edges of the view to the left and right edges of the containing superview with a spacing of 20 and 30 points respectively 20 mybutton1 30 The language also allows priorities to be declared The following excerpt specifies that the width of mybutton1 must be greater than or equal to 70 points with a priority value of 500 mybutton1 70 500 Of particular importance however is the fact that the language may be used to construct multiple constraints in a single sequence for example V 20 mybutton1 70 500 mybutton2 mybutton1 30 mybutton3 Using the constraintsWithVisualFormat Method As previously described visual language format based constraints are created via a call to the constraintsWithVisualFormat method of the NSLayoutConstraint class There are however a number of other arguments that the method is able to accept The syntax for the method is as follows NSLayoutConstraint constraintsWithVisualFormat visual format string options options metrics metrics views views dictionary The visual format string is of course the visual format language string that describes the constraints that are to be created The options are required to be set when the constraint string references more than one view The purpose of this is to indicate how the views are to be aligned and the value must be of type NSLayoutFormatOptions for example AlignAllLeft AlignAllRight AlignAllTop AlignAllBaselines etc The metrics argument is an optional NSDictionary object containing the corresponding values for any constants referenced in the format string Finally the views dictionary is an NSDictionary object that contains the view objects that match the view names referenced in the format string When using a visual format string that will result in the creation of multiple

    Original URL path: http://www.techotopia.com/index.php/Understanding_the_iOS_8_Auto_Layout_Visual_Format_Language_in_Swift (2016-02-13)
    Open archived version from archive


  • Using Size Classes to Design Universal iOS User Interfaces - Techotopia
    any particular size class As the mouse pointer is moved over the size class selection grid the blue area will change to reflect different size classes Hovering the mouse pointer over the bottom left hand square within the grid Figure 24 4 for example displays the traits of the corresponding size class and provides the opportunity to change to the Compact Width and Regular Height size class Figure 24 4 Clicking within the grid location will make this size class the active class and the view controller layout canvas in the storyboard will change size to represent an iPhone screen in portrait orientation Once a size class has been selected layout changes made to the storyboard will apply only to that class Note also that the size class indicator now changes to wCompact hRegular Figure 24 5 reflecting the currently selected size class It is also worth noting that the status bar has changed to a blue background This is intended as a subtle reminder that the layout is no longer in the wAny hAny mode and that layout changes will not apply to all size classes Figure 24 5 A Universal User Interface Tutorial The remainder of this chapter will work through the creation of a universal layout example Create a new Xcode Single View Application project named UniversalDemo with the language option set to Swift and the Devices menu set to Universal Once the project has been created select the Main storyboard file display the File Inspector in the Utilities panel and make sure that both the Use Auto Layout and Use Size Classes options are enabled Designing the iPad Layout The iPad layout will serve as the base configuration for the user interface so begin by making sure that the size class settings for Interface Builder are currently set to wAny hAny Add an ImageView and two Buttons to the view controller layout so that the user interface layout resembles that of Figure 24 6 Edit the text on the button views to read Send and Edit respectively Figure 24 6 Select the Image View instance in the layout and use the Pin menu to set constraints on the top and left edges of the view of 0 with the Constrain to margins option enabled as shown in Figure 24 7 and click on the Add 2 Constraints button Figure 24 7 Ctrl click and drag diagonally across the Image View as shown in Figure 24 8 On releasing the line select Aspect Ratio from the resulting menu Figure 24 8 eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters With the Image View still selected display the Pin menu a second time and enable the right hand edge spacing to nearest neighbor constraint Click on the drop down menu for the constraint value and select the View option Figure 24 9 so that the constraint is relative to the parent view and not one of the Button views Click on the Add 1 Constraint button to commit the change Figure 24 9 With the Image View still selected Shift click on the Edit button so that both views are selected Display the Auto Layout Align menu enable the Vertical Centers constraint option and add the constraint Select just the Edit button and using the Pin menu configure spacing to nearest neighbor constraints for both the trailing and leading edges of the view with the Constrain to margins option disabled Finally select the Send button display the Pin menu and configure leading trailing and bottom spacing to nearest neighbor constraints using the current values with the Constrain to margins option disabled Use the size classes menu to change the current size class to wRegular hRegular and verify that the layout appears correctly Return to wAny hAny and make any necessary adjustments Be sure to return the size classes setting to wAny hAny before proceeding with the tutorial Adding Universal Image Assets The next step in the tutorial is to add some image assets to the project The images can be found in the universal images directory of the code samples download which can be obtained from http www ebookfrenzy com direct ios8 Within the project navigator panel locate and click on the Images xcassets entry and once loaded select the Editor New Image Set menu option Double click on the new image set which will have been named Image and rename it to Sunset Locate the sunset wAny hAny png file in a Finder window and drag and drop it onto the 1x image box as illustrated in Figure 24 10 Figure 24 10 Return to the Main storyboard file select the Image View and display the Attributes Inspector panel Click on the down arrow at the right of the Image field and select Sunset from the resulting menu The Image View in the view controller canvas will update to display the sunset image from the asset catalog Perform a test run of the app on a physical iPad device or iPad simulator and verify that the user interface matches that designed in Interface Builder Designing the iPhone Layout Use the size classes menu to switch Interface Builder into Wcompact hRegular mode so that the view controller canvas changes to represent the size proportions for the iPhone device family in portrait mode The iPhone layout in this example will differ from the iPad layout in a number of ways In the first instance the Edit button will be absent from the iPhone layout To achieve this select the Edit button display the Attributes Inspector and scroll down to the last attribute setting which consists of a check box labelled Installed Click on the button to the left of the installed check box and from the resulting menu select the Compact Width Regular Height current menu option

    Original URL path: http://www.techotopia.com/index.php/Using_Size_Classes_to_Design_Universal_iOS_User_Interfaces (2016-02-13)
    Open archived version from archive

  • Using Storyboards in Xcode 6 - Techotopia
    line to the scene 2 view Upon releasing the mouse button a menu will appear Select the show menu option to establish the segue Figure 25 5 As more scenes are added to a storyboard it becomes increasingly difficult to see more than a few scenes at one time on the canvas To zoom out double click on the canvas To zoom back in again simply double click once again on the canvas Ctrl clicking on the storyboard canvas background will provide a menu containing a number of zoom level options Configuring Storyboard Transitions Xcode provides the option to change the visual appearance of the transition that takes place during a segue By default a Cover Vertical transition is performed whereby the new scene slides vertically upwards from the bottom of the view to cover the currently displayed scene To change the transition select the corresponding segue line display the Attributes Inspector View Utilities Show Attributes Inspector and modify the Transition setting In Figure 25 6 the transition has been changed to Cross Dissolve Figure 25 6 If animation is not required during the transition turn off the Animates option To delete a segue from a storyboard simply select the segue line in the storyboard canvas and press the keyboard delete key Compile and run the application Note that touching the Go to Scene 2 button causes Scene 2 to appear eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters Associating a View Controller with a Scene At this point in the example we have two scenes but only one view controller the one created by Xcode when we selected Single View Application Clearly in order to be able to add any functionality behind scene 2 it too will need a view controller The first step therefore is to add the class source file for a view controller to the project Ctrl click on the Storyboard target at the top of the project navigator panel and select New File from the resulting menu In the new file panel select Source listed under iOS in the left hand panel followed by Cocoa Touch Class in the main panel and click Next to proceed On the options screen verify that the Subclass of menu is set to UIViewController and that the Also create XIB file option is deselected since the view already exists in the storyboard there is no need for an XIB user interface file and name the class Scene2ViewController Select the Main storyboard file in the project navigator panel and select the View Controller button located in the panel beneath the Scene 2 view as shown in Figure 25 7 Figure 25 7 With the view controller for scene 2 selected within the storyboard canvas display the Identity Inspector View Utilities Identity Inspector and change the Class from UIViewController

    Original URL path: http://www.techotopia.com/index.php/Using_Storyboards_in_Xcode_6 (2016-02-13)
    Open archived version from archive

  • Using Xcode 6 Storyboards to Create an iOS 8 Tab Bar Application - Techotopia
    provided the file necessary for a single view controller based application named ViewController swift A Main storyboard file has also been created To start with an entirely clean project select the ViewController swift file in the project navigator panel and press the keyboard Delete key to remove the file from the project choosing the option to move the file to the trash when prompted to do so Adding the View Controllers for the Content Views The ultimate goal of this chapter is to create a tab bar based application consisting of two tabs with corresponding views each of these will require a view controller The first step therefore is to add the view controller for the first view To achieve this select the File New File menu option and on the resulting panel select Source from beneath the iOS heading in the left hand panel and Cocoa Touch Class from the list of templates Click Next and on the next screen name the new class Tab1ViewController and change the Subclass of menu to UIViewController Ensure that the Also create XIB file option is switched off before clicking Next Select the desired location for the creation of the class files before clicking on Create Repeat the above steps to add a second view controller class named Tab2ViewController The scene within the storyboard file now needs to be associated with one of these view controller classes Select the Main storyboard file and select the scene added by Xcode so that it is highlighted with a blue border before displaying the Identity Inspector panel View Utilities Show Identity Inspector Within the inspector panel change the Class setting from UIViewController to Tab1ViewController The second view controller may be added to the storyboard simply by dragging and dropping one from the Object Library panel View Utilities Show Object Library onto the storyboard canvas Once it has been added follow the same steps to change the view controller class within the Identity Inspector panel this time selecting Tab2ViewController in the Class field eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters Adding the Tab Bar Controller to the Storyboard As previously explained the navigation between view controllers in a Tab Bar based interface is handled by a Tab Bar Controller It will be necessary therefore to add one of these to our storyboard Begin by selecting the Main storyboard file in the Xcode project navigator panel In order to add a Tab Bar Controller to the storyboard select the Tab1ViewController in the storyboard design area and select the Editor Embed In Tab Bar Controller menu option The Tab Bar Controller will subsequently appear in the storyboard already connected to the Tab 1 View Controller as shown in Figure 26 1 Figure 26 1 A relationship now needs to be established between the Tab2ViewController class and

    Original URL path: http://www.techotopia.com/index.php/Using_Xcode_6_Storyboards_to_Create_an_iOS_8_Tab_Bar_Application (2016-02-13)
    Open archived version from archive

  • An Overview of iOS 8 Table Views and Xcode 6 Storyboards - Techotopia
    alphabetical or numerical sorting Self Sizing Table Cells iOS 8 has introduced a new feature of table views in the form of self sizing cells With self sizing each row of a table is sized according to the content of the corresponding cell based on the Auto Layout constraints applied to the cell contents Self sizing will be demonstrated in the next chapter entitled Using Xcode 6 Storyboards to Build Dynamic TableViews with Prototype Table View Cells but is of particular importance when the labels in a cell are configured to use dynamic type eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters Dynamic Type iOS 7 provided a way for the user to select a preferred text size which applications are expected to adopt when displaying text The current text size can be configured on a device via the Settings Display Brightness Text Size screen which provides a slider to adjust the font size as shown in Figure 27 3 Figure 27 3 Almost without exception the built in iOS apps adopt the font size setting selected by the user when displaying text Apple also recommends that third party apps also conform to the user s text size selection and with iOS 8 support for dynamic type has been extended to table views This is achieved by specifying a preferred text style setting for the font of any custom labels in a cell iOS specifies a variety of different preferred text styles for this purpose including headings sub headings body captions and footnotes The text style used by a label can be configured using Interface Builder or in code To configure the text style in Interface Builder select the label display the Attributes Inspector and click on the T button in the font setting field as demonstrated in Figure 27 4 From the drop down menu click on the Font menu button and select an item from the options listed under the Text Styles heading Figure 27 4 The preferred font is configured in code by setting the preferredFontForTextStyle property to one of the following pre configured text style values UIFontTextStyleHeadline UIFontTextStyleSubheadline UIFontTextStyleBody UIFontTextStyleFootnote UIFontTextStyleCaption1 UIFontTextStyleCaption2 The following code for example sets a dynamic type font on a label using the headline font style cell myLabel font UIFont preferredFontForTextStyle UIFontTextStyleHeadline Clearly the text size selected by a user will dictate the size of any cells containing labels that use dynamic type hence the importance of using self sizing to ensure the table rows are displayed using an appropriate height Table View Cell Styles In addition to the style of the Table View itself different styles may also be specified for the individual table cells unless custom table cells are being used The iOS 8 SDK currently supports four different cell styles UITableViewCellStyleDefault only the labelText in black and

    Original URL path: http://www.techotopia.com/index.php/An_Overview_of_iOS_8_Table_Views_and_Xcode_6_Storyboards (2016-02-13)
    Open archived version from archive

  • Using Storyboards and Swift to Build Dynamic TableViews with Prototype Table View Cells - Techotopia
    this is only possible when the storyboard view is zoomed in With this in mind verify that the storyboard is zoomed in and then drag and drop a Label and an Image View object onto the prototype table cell Resize and position the items so that the cell layout resembles that illustrated in Figure 28 5 making sure to stretch the label object so that it extends toward the mid point of the cell width Figure 28 5 Select the Image View and using the Auto Layout Pin menu set Spacing to nearest neighbor constraints on the top left and bottom edges of the view with the Constrain to margins option switched off Before adding the constraints also enable the Width constraint Select the Label view display the Auto Layout Align menu and add a Vertical Center in Container constraint to the view With the Label still selected display the Pin menu and add a Spacing to nearest neighbor constraint on the left hand edge of the view with the Constrain to margins option off Having configured the storyboard elements for the table view portion of the application it is time to begin modifying the table view and cell subclasses Modifying the AttractionTableViewCell Class Within the storyboard file a label and an image view were added to the prototype cell which in turn has been declared as an instance of our new AttractionTableViewCell class In order to manipulate these user interface objects from within our code we need to establish two outlets connected to the objects in the storyboard scene Begin therefore by selecting the image view object displaying the Assistant Editor and making sure that it is displaying the content of the AttractionTableViewCell swift file If it is not use the bar across the top of the editor panel to select this file Ctrl click on the image view object in the prototype table cell and drag the resulting line to a point just below the class declaration line in the Assistant Editor window Release the line and use the connection panel to establish an outlet named attractionImage Repeat these steps to establish an outlet for the label named attractionLabel Creating the Table View Datasource Dynamic Table Views require a datasource to provide the data that will be displayed to the user within the cells By default Xcode has designated the AttractionTableViewController class as the datasource for the table view controller in the storyboard Consequently it is within this class that we can build a very simple data model for our application consisting of a number of arrays The first step is to declare these as properties in the AttractionTableViewController swift file import UIKit class AttractionTableViewController UITableViewController var attractionImages String var attractionNames String var webAddresses String In addition the arrays need to be initialized with some data when the application has loaded making the viewDidLoad method an ideal location Select the AttractionTableViewController swift file within the project navigator panel and modify the method as outlined in the following code

    Original URL path: http://www.techotopia.com/index.php/Using_Storyboards_and_Swift_to_Build_Dynamic_TableViews_with_Prototype_Table_View_Cells (2016-02-13)
    Open archived version from archive

  • Implementing iOS 8 TableView Navigation using Storyboards in Xcode 6 and Swift - Techotopia
    The detail view will contain a button which when selected by the user will navigate back to the table view This functionality will be made possible by the addition of a Navigation Controller to the storyboard This can be added by selecting the Attraction Table View Controller item in the storyboard so that it highlights in blue and then selecting the Xcode Editor Embed In Navigation Controller menu option Once performed the storyboard will appear as outlined in Figure 29 2 Figure 29 2 Establishing the Storyboard Segue When the user selects a row within the table view a segue needs to be triggered to display the attraction detail view controller In order to establish this segue Ctrl click on the prototype cell located in the Attraction Table View Controller scene and drag the resulting line to the Attraction Detail View Controller scene Upon releasing the line select the show option from the resulting menu The storyboard will update to display a segue connection between the table view cell and the view controller In code that will be implemented later in this chapter it will be necessary to reference this specific segue In order to do so it must therefore be given an identifier Click on the segue connection between Attraction Table View Controller and Attraction Detail View Controller display the Attributes Inspector View Utilities Show Attributes Inspector and change the Identifier value to ShowAttractionDetails In addition a toolbar should have appeared in both scenes Double click on the center of the Attraction Table View Controller toolbar and change the title to Attractions Next drag a Navigation Item view from the Object Library and drop it onto the toolbar of the Attraction Detail View Controller Double click on the Title and change it to Attraction Details Figure 29 3 Build and run the application and note that selecting a row in the table view now displays the second view controller which in turn has a button in the toolbar to return to the Attractions table view Clearly we now need to do some work on the AttractionDetailViewController class so that information about the selected tourist location is displayed in the view eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters Modifying the AttractionDetailViewController Class For the purposes of this example application the attraction detail view is going to display a web view loaded with a web page relating to the selected tourist attraction In order to achieve this the class is going to need a UIWebView object which will later be added to the view In addition to the web view the class is also going to need an internal data model that contains the URL of the web page to be displayed It will be the job of the table view controller to update this variable prior to

    Original URL path: http://www.techotopia.com/index.php/Implementing_iOS_8_TableView_Navigation_using_Storyboards_in_Xcode_6_and_Swift (2016-02-13)
    Open archived version from archive

  • An iOS 8 Swift Split View Master-Detail Example - Techotopia
    reads Master and enter Favorite Web Sites as the new title as outlined in Figure 30 1 Figure 30 1 Configuring Master View Items The master view controller created for us by Xcode is actually a subclass of UITableView The next step therefore is to configure the table view to display the list of web sites For this purpose we will need to configure two array objects to store the web site names and corresponding URL addresses Select the MasterViewController swift file and modify it as follows to declare these two arrays import UIKit class MasterViewController UITableViewController var siteNames String var siteAddresses String var detailViewController DetailViewController nil var objects NSMutableArray Having declared the arrays modify the MasterViewController swift file further to initialize the arrays in the viewDidLoad method Note that Xcode has already added some code to the viewDidLoad method for the template example so be sure to remove this before adding the new code below override func viewDidLoad super viewDidLoad siteNames Yahoo Google Apple eBookFrenzy siteAddresses http www yahoo com http www google com http www apple com http www ebookfrenzy com if let split splitViewController let controllers split viewControllers detailViewController controllers controllers count 1 topViewController as DetailViewController There are a number of methods that must be implemented in order for the items to appear within the table view object Fortunately Xcode has already placed template methods for us to use in the MasterViewController swift file First modify the numberOfRowsInSection method to notify the table view of the number of items to be displayed in this case a value equal to the number of items in our siteNames array Since there is only one section in the table also modify the numberOfSectionsInTableView method accordingly Note that Xcode has once again added some code for the template example so be sure to remove this code where necessary NSInteger numberOfSectionsInTableView UITableView tableView return 1 NSInteger tableView UITableView tableView numberOfRowsInSection NSInteger section return siteNames count Next modify the cellForRowAtIndexPath method to return the item to be displayed using the row number argument as an index into the siteNames array override func tableView tableView UITableView cellForRowAtIndexPath indexPath NSIndexPath UITableViewCell let cell tableView dequeueReusableCellWithIdentifier Cell forIndexPath indexPath as UITableViewCell cell textLabel text siteNames indexPath row return cell Click on the run button located in the Xcode toolbar to test the current state of the application using a physical iPad or iPhone 6 Plus device or a corresponding simulator as the target Once the application loads rotate the device into landscape mode using the Hardware Rotate Left menu if running on a simulator Figure 30 2 At this point the items in the master panel actually load the detail view onto the master panel when selected and the detail panel still displays the place holder label provided by Xcode when the project was first created The next step is to change this behavior and add the web view to the detail view controller eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7

    Original URL path: http://www.techotopia.com/index.php/An_iOS_8_Swift_Split_View_Master-Detail_Example (2016-02-13)
    Open archived version from archive



  •