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 7 Auto Layout Visual Format Language - Techotopia
    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 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 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 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 NSLayoutFormatAlignAllLeft NSLayoutFormatAlignAllRight NSLayoutFormatAlignAllTop NSLayoutFormatAlignAllBaselines 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 The iOS 7 SDK provides a convenience macro that can be used to construct this dictionary for the objects referenced in the format string for example NSDictionary viewsDictionary NSDictionaryOfVariableBindings mybutton1 mybutton2

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

  • Using Storyboards in Xcode 5 - Techotopia
    To zoom out double click on the canvas To zoom back in again simply double click once again on the canvas Zoom buttons are also provided in the bottom right hand corner of the design canvas Note that when zoomed out it will not be possible to drag and drop items from the Object Library onto the scenes 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 20 6 the transition has been changed to Cross Dissolve Figure 20 6 If animation is not required during the transition turn off the Animates option To delete a segue from a storyboard simply select the arrow 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 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 files 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 Cocoa Touch from the iOS category in the left hand panel followed by Objective C 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 Targeted for iPad and With XIB for user interface options are both 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 20 7 Figure 20 7 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 view controller for scene 2 selected within the storyboard canvas display the Identity Inspector View Utilities Identity Inspector and change the Class from UIViewController to Scene2ViewController Figure 20 8 Scene 2 now has a view controller and corresponding source files where code may be written to implement any required functionality Select the label object in scene

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

  • Using Xcode 5 Storyboards to Create an iOS 7 Tab Bar Application - Techotopia
    Since this view controller presents the view that will be displayed when the user touches the first tab on the tab bar we will name this class Tab1ViewController To achieve this select the TabBarViewController h file and use the mouse to highlight the TabBarViewController class name in the editing panel With the name highlighted select the Edit Refactor Rename menu option In the resulting panel enter Tab1ViewController into the text box and click on Preview In the preview panel select the Save button followed by the option to Disable snapshots Adding the View Controller for the Second Content View The ultimate goal of this chapter is to create a tab bar based application consisting of two tabs with corresponding views Xcode has already created the first view controller for us and we have subsequently renamed this class The next step therefore is to add the view controller for the second view To achieve this select the File New File menu option and on the resulting panel select Cocoa Touch from beneath the iOS heading in the left hand panel and Objective C class from the list of templates Click Next and on the next screen name the new class Tab2ViewController and change the Subclass of menu to UIViewController Ensure that the options to target iPad and create an XIB file are switched off before clicking Next Select the desired location for the creation of the class files before clicking on Create 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 and note as illustrated in Figure 21 1 that the storyboard currently only contains the original view controller instance added for us by Xcode when the project was created Figure 21 1 In order to add a Tab Bar Controller to the storyboard select the Tab1 View Controller 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 Bar Controller as shown in Figure 21 2 Figure 21 2 Now that the Tab Bar Controller has been added the next task is to add a view controller to the storyboard that will correspond to the Tab2ViewController class previously added to the project 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 a Second View Controller to the Storyboard 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 Once the new view controller has been

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

  • An Overview of iOS 7 Table Views and Xcode 5 Storyboards - Techotopia
    number of methods that define title information how many rows of data are to be displayed how the data is divided into different sections and most importantly supplies the table view with the cell objects to be displayed The delegate implements the UITableViewDelegate protocol and provides additional control over the appearance and functionality of the table view including detecting when a user touches a specific row defining custom row heights and indentations and also implementation of row deletion and editing functions Table View Styles Table views may be configured to use either plain or grouped style In the grouped style the rows are grouped together in sections separated by optional headers and footers For example Figure 22 1 shows a table view configured to use the grouped style Figure 22 1 In the case of the plain style the items are listed without separation and using the full width of the display Figure 22 2 Table Views using plain style can also be indexed whereby rows are organized into groups according to specified criteria such as alphabetical or numerical sorting 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 7 SDK currently supports four different cell styles UITableViewCellStyleDefault only the labelText in black and left aligned UITableViewCellStyleSubtitle labelText in black and left aligned with the detailLabeltext positioned beneath it in a smaller font using a gray foreground UITableViewCellStyleValue1 labelText in black left aligned and the smaller detailLabelText in blue on the same line and right aligned UITableViewCellStyleValue2 labelText in blue on left side of cell right aligned and detailedLabelText on right of cell left aligned and black 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 Table View Cell Reuse A table view is at the basic level comprised of a UITableView object and a UITableViewCell for each row to be displayed The code for a typical iOS 7 application using a table view will not directly create instances of a cell The reasoning behind this becomes evident when performance and memory requirements are taken into consideration Consider for example a table view that is required to display 1000 photo images It can be assumed with a reasonable degree of certainty that only a small percentage of cells will be visible to the user at any one time If the application was permitted to create each of the 1000 cells in advance the device would very quickly run into memory and performance limitations Instead the application begins by registering with the table view object the class to be used for cell objects along with the reuse identifier previously assigned to that class If the cell class was written in code the registration is performed

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

  • Using Xcode 5 Storyboards to Build Dynamic TableViews with Prototype Table View Cells - Techotopia
    this example each table cell needs to display an image view and two labels which in turn will be connected to outlets that we will later declare in the CarTableViewCell subclass Much like Interface Builder components may be dragged from the Object Library panel and dropped onto a scene within the storyboard Note however that this is only possible when the storyboard view is zoomed in With this in mind verify that the storyboard is zoomed in using the controls in the bottom right hand corner of the canvas and then drag and drop two Labels 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 23 4 making sure to stretch the label objects so that they extend toward the right hand edge of the cell Figure 23 4 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 CarTableViewCell Class Within the storyboard file two labels and an image view were added to the prototype cell which in turn has been declared as an instance of our new CarTableViewCell class In order to manipulate these user interface objects from within our code we need to establish three 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 CarTableViewCell h 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 interface line in the Assistant Editor window Release the line and use the connection panel to establish an outlet named carImage Figure 23 5 Repeat these steps to establish outlets for the two labels named makeLabel and modelLabel respectively Once the connections are in place the CarTableViewCell h file should read as follows import UIKit UIKit h interface CarTableViewCell UITableViewCell property nonatomic strong IBOutlet UIImageView carImage property nonatomic strong IBOutlet UILabel makeLabel property nonatomic strong IBOutlet UILabel modelLabel end 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 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 CarTableViewController class as the datasource for the table view controller in the storyboard It is within this class therefore 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 CarTableViewController h file import UIKit

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

  • Implementing iOS 7 TableView Navigation using Storyboards in Xcode 5 - Techotopia
    Navigation Controller to the storyboard This can be added by selecting the Car 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 24 2 Figure 24 2 Establishing the Storyboard Segue When the user selects a row within the table view a segue needs to be triggered to display the car detail view controller In order to establish this segue Ctrl click on the prototype cell located in the Car Table View Controller scene and drag the resulting line to the Car Detail View Controller scene Upon releasing the line select the push 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 Car Table View Controller and Car Detail View Controller display the Attributes Inspector View Utilities Show Attributes Inspector and change the Identifier value to ShowCarDetails In addition a toolbar should have appeared in both scenes Double click on these toolbars and change the title to Cars and Car Details respectively Figure 24 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 Cars table view Clearly we now need to do some work on the CarDetailViewController class so that details about the selected car are 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 CarDetailViewController Class For the purposes of this example application the car detail view is going to display the make and model of the selected car together with a photograph In order to achieve this the class is going to need outlets to two labels and a UIImageView object which will later be added to the view In addition to the outlets the class is also going to need an internal data model that contains information about the car It will be the job of the table view controller to update this model prior to the segue occurring so that it reflects data on the selected car For the sake of simplicity the data model will take the form of an NSArray object Select the CarDetailViewController h file and modify it as follows to declare this array import UIKit UIKit h interface CarDetailViewController UIViewController property strong nonatomic NSArray carDetailModel end The next step is to design the user interface for the detail view and connect the

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

  • Using an Xcode 5 Storyboard to Create a Static Table View - Techotopia
    the class from UITableViewController to StaticTableViewController Changing the Table View Content Type By default Xcode makes the assumption that the table view is to be dynamic The most obvious indications of this are the presence of a Prototype Cell within the table view and the words Prototype Content in the view Click within the grey area of the table view and display the Attributes Inspector panel The Content attribute will currently be set to Dynamic Prototypes so use the menu to change the attribute to Static Cells At this point the table view within the storyboard will change to display a static table containing three rows as illustrated in Figure 25 1 Figure 25 1 Designing the Static Table With a static table view added to the project the full power of Interface Builder is available to us to design the layout and content of the table and cells The first step is to change the table view style With the table view selected in the storyboard and the Attributes Panel displayed change the Style attribute to Grouped and the Sections attribute to 2 The table view should now consist of two group sections with three rows per section For the purposes of this example we only need two rows in the top section so click on the third row to highlight it and press the delete key on the keyboard Note that additional rows may be added if required by selecting the corresponding table view section and changing the Rows property In the case of the bottom section only one row is required so Command click on the bottom two rows and delete them from the view Select the top section by clicking on the shaded area immediately below the cells note that sections may also be selected by clicking on the Table View Section item in the toolbar strip located across the top of the storyboard editor and also from the hierarchy list located in the Document Outline panel of the Xcode window Within the Attributes Inspector change the Header property to Car Details Repeat this step on the lower section to change the header to Car Photo Next stretch the height of the single cell in the bottom section so that it fills the remainder of the table view such that the table view appears as illustrated in the following figure Figure 25 2 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 Items to the Table Cells Using the Object Library panel drag and drop an Image View object into the cell in the bottom section and resize it to fill most of the available space Also drag and drop labels into the two cells in the top section and set appropriate text properties so that the layout resembles that of Figure 25 3

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

  • An iPad iOS 7 Split View and Popover Example - Techotopia
    that will be necessary for this example will be to change the user interface of the detail view pane and to modify the title of the master pane The rest of the storyboard will remain unchanged To change the title of the master pane locate it within the storyboard canvas double click on the title text which currently reads Master and enter Favorite Web Sites as the new title as outlined in Figure 26 1 Figure 26 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 SplitViewMasterViewController h file and modify it as follows to declare these two arrays import UIKit UIKit h class SplitViewDetailViewController interface SplitViewMasterViewController UITableViewController property nonatomic retain NSArray siteNames property nonatomic retain NSArray siteAddresses property strong nonatomic SplitViewDetailViewController detailViewController end Having declared the arrays modify the SplitViewMasterViewController m file 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 void viewDidLoad super viewDidLoad siteNames NSArray alloc initWithObjects Yahoo Google Apple eBookFrenzy nil siteAddresses NSArray alloc initWithObjects http www yahoo com http www google com http www apple com http www ebookfrenzy com nil self detailViewController SplitViewDetailViewController self splitViewController viewControllers lastObject topViewController 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 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 SplitViewMasterViewController m 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 UITableViewCell tableView UITableView tableView cellForRowAtIndexPath NSIndexPath indexPath static NSString CellIdentifier Cell UITableViewCell cell tableView dequeueReusableCellWithIdentifier CellIdentifier if cell nil cell UITableViewCell alloc initWithStyle UITableViewCellStyleDefault reuseIdentifier CellIdentifier NSDate object objects indexPath row cell textLabel text object description cell textLabel text siteNames indexPath row return cell Click on the Run button located

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



  •