concept view in category ios

appears as: views, view, views, A view, view, The views, The view
Hello! iOS Development

This is an excerpt from Manning's book Hello! iOS Development.

  • Editor— The place where you’ll type in code. It shows the file currently selected in either of the two file-navigation controls. In the figure, the editor is shown after we selected HWAppDelegate.h. To help you be productive in Xcode, we’ll go over the menus, hotkeys, and views that let you edit a project.
  • A view is what you see on the screen and interact with. When you draw sketches of iPhone apps or use Interface Builder, you’re drawing the view. To make things easier later, you keep each part of the user interface in a separate view. That means each button you click, text box you fill in, or check box you check is its own view. Views do more than just show the user what is going on—they’re also responsible for letting the rest of your application know they’re being touched. On that grocery list, the list you see is the view. Each item is in its own view, and when you touch the item to cross it off the list, its view is the part of the app that is first to know.

    So, using a grocery list app example again, when you touch the Grocery Item View on your phone to indicate that you’ve put the item in your shopping cart, the view tells the Grocery Item View Controller that it’s been touched. The controller tells the model to remember that it’s been taken, and then it tells the view to show it crossed out.

    The best way to learn MVC is to open apps on your phone and start seeing their features as models, views, and controllers. Every app on your phone can be broken down into these parts. You don’t have to do it this way, and your app will still work if you put something in the wrong place, but it’s much easier to understand and work on your application if you keep the components straight.

    Hello Swift!: iOS app programming for kids and other beginners

    This is an excerpt from Manning's book Hello Swift!: iOS app programming for kids and other beginners.

    Think of a view as the screen people see when they use your app. Your app will have only one view: the one with the words Hello World! on it. Later in this chapter, you’ll build an app with two views.

    //
    //  ViewController.swift
    //  MessageMagic
    //
    //  Created by Tanmay Bakshi on 2/13/15.
    //  Copyright (c) 2015 TBSS. All rights reserved.
    //
    import UIKit
    
    class ViewController: UIViewController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically
             from a nib.
        }
    
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
    }
    iOS Development with Swift

    This is an excerpt from Manning's book iOS Development with Swift.

    1.4.2. View controllers and views

    Everything that you see in your scene is a type of view (or is rendered within a view). Text fields, labels, buttons, switches, and images are all examples of types of views. Views can contain other views and be contained within other views. At the root of a scene is one parent view that contains everything visual in your scene.

    If you have experience in programming, you’ll most likely have come across the design pattern Model-View-Controller, where the view is separated from the model and the controller. We’ll come back to this concept in chapter 4 when we look at models, but for now let’s consider the view and the controller.

  • As you’ve seen, views are the visual components of an app. They can also provide visual feedback on interaction and report on user interaction. They’re typically generic and reusable. Apple provides many views for you in the UIKit that are ready to go, such as labels, images, and switches. You’ve already seen that the distance converter app will contain a root view that then contains standard label and text field views.
  • To instantiate a UIView, you need to pass in the view’s frame dimensions using a structure type called CGRect. Get the width and height of the root view with view’s bounds property. You can then set its background color to red and add it to the scene’s root view.

  • Add the following to the end of the viewDidLoad method:
    redView = UIView(frame: CGRect(x: 0, y: 0,           1
        width: view.bounds.width,                        1
        height: view.bounds.height / 2))                 1
    redView.backgroundColor = UIColor.red                2
    view.addSubview(redView)                             3
    • 1 Instantiates view
    • 2 Ensures that the view lives up to its name
    • 3 Uses UIView’s addSubview method to add as a subview of the scene’s root view
  • Both the frame and bounds of a view refer to a rectangle, defined by a CGRect object that contains the size (width and height) and origin (x and y) of the view. The origin of a CGRect object usually refers to the upper-left corner.

    The difference between frame and bounds is that frame is seen from the perspective of the view’s superview coordinate system, and bounds is seen from the perspective of the view’s own coordinate system. As you can see in the view in the example, the size of the bounds is often the same as the size as the frame of a view. The origin, on the other hand, often differs, depending on the perspective.

    If you apply any transformations to the rectangle, however, such as scaling or rotation, the size of a view can look different from the perspective of a view’s own coordinate system or its superview’s. Scale a view 50% such as in the example, and the size of its bounds won’t change, but from the perspective of its superview, the size of its frame has shrunk by half.

    Anyone Can Create an App: Beginning iPhone and iPad programming

    This is an excerpt from Manning's book Anyone Can Create an App: Beginning iPhone and iPad programming.

    The single-view application is just that: one view that Apple has built for you, which you need to add something to. When you think about a view, think of a blank page in a book. There are no words or pictures on the page yet—it’s empty. And it has no other parts to it. You can’t flip the page to see what’s next, because there isn’t a next page.

  • Add a button and a label to the view.
  • Add a text box to the view.
  • Figure 13.1. The ViewController.swift file controls the view.
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
      }
    
      override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
      }
    iOS 7 in Action

    This is an excerpt from Manning's book iOS 7 in Action.

    On the left side of the window, click Main.storyboard to bring up Xcode’s interface editor. Your interface will be fairly simple and straightforward because you’re showing only one piece of information on the screen, which is the current time. You’re going to add a label to the view in the scene that was created for you in your app’s storyboard. This label will be used to display the current time.

    You also interact with your apps differently. Instead of using peripherals such as a keyboard and mouse as input devices, you use your fingers. The appearance and design should feel natural to users. You should take all of this into account when creating and designing the views that make up your apps.

    In this chapter we’ll go over the different parts of what you see in an app—its windows, its views, and the view controllers that manage them. You’ll learn about the different controls you can use within each view of your app, such as buttons, labels, and text fields. You’ll then learn how to visually arrange and organize the views within your application, better known as storyboarding. First, we’ll revisit the Hello Time app you created in chapter 1 and add more functionality to it.

    Listing 2.2. Changing the view depending on orientation
    - (void) willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { CGRect timeFrame = self.timeLabel.frame; float viewHeight = self.view.frame.size.height; float viewWidth = self.view.frame.size.width; float fontSize = 30.0f; BOOL hideButton = YES; if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) { fontSize = 40.0f; timeFrame.origin.y = (viewWidth / 2) - timeFrame.size.height; timeFrame.size.width = viewHeight; } else { hideButton = NO; timeFrame.origin.y = (viewHeight / 2) - timeFrame.size.height; timeFrame.size.width = viewWidth; } [self.modeButton setHidden:hideButton]; [self.timeLabel setFont:[UIFont boldSystemFontOfSize:fontSize]]; [self.timeLabel setFrame:timeFrame]; } - (NSUInteger) supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape; }

    2.2.1. Screens, windows, and views

    Everything you see in an app is primarily made up of views. These views are displayed within a window, and that window is contained within a screen. Take a look at the anatomy of a view you’d see within your Hello Time application by focusing on figure 2.10.

    Figure 2.10. The Hello Time app, which has a label and button within a view, which is contained within a window inside a screen
    iOS in Practice

    This is an excerpt from Manning's book iOS in Practice.

    iOS development also relies heavily on the Model-View-Controller (MVC) architecture pattern. MVC is the separation of your development into three aspects: model, view, and controller. The model is the data layer (for example, the database in a project). The view is the UI that the user interacts with. The controller is between the view and the model, and it translates the user interaction to logic and accesses data as necessary.

    Figure 3.6. Dropping a Round Rect Button onto the view

    Delete the toolbar by selecting it and typing Command-x. Instead of dropping an image view on the controller window, drop a view. Now for the toolbar and image view: drop the toolbar, placing it on the lower end of the view. Finally, drop an image view into the white area left in the view. You drop the image view after the toolbar so that IB will automatically size it to fill the rest of the view (see figure 3.13).

    Figure 3.13. Dropping the image view in the view after the toolbar to auto-size

    Now the view controller’s view is a UIView. The UIView can contain multiple sub-views. In your case, it has an image view and toolbar. A UIToolbar is also a subclass of UIView.

    Objective-C Fundamentals

    This is an excerpt from Manning's book Objective-C Fundamentals.

    1.4.1. Adding controls to a view

    The first step in defining the user interface for your game is to position the required user interface controls onto the view.

    To add controls, find them in the Library window, which contains a catalog of available user interface controls, and drag and drop them onto the view. If the Library window isn’t visible, you can open it via the View > Utilities > Object Library menu option (Control-Option-Cmd-3). For the Coin Toss game, you require two Labels and two Rounded Rect Buttons, so drag two of each control onto the view. The process of dragging and dropping a control onto the view is shown in figure 1.7.

    Figure 1.7. Dragging and dropping new controls onto the view. Notice the snap lines, which help ensure your user interface conforms to the iOS Human Interface Guidelines (HIG).

    After you drag and drop the controls onto the view, you can resize and adjust their positions to suit your aesthetics. The easiest way to change the text displayed on a button or label control is to double-click the control and begin typing. To alter other properties, such as font size and color, you can use the Attributes Inspector pane, which can be displayed via the View > Utilities > Attributes Inspector menu option (Alt-Cmd-4). While styling your view, you can refer back to figure 1.2 for guidance.

    didReceiveMemoryWarning
        // Releases the view if it doesn't have a superview.
    
    viewDidUnload
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    iOS 4 in Action: Developing iPhone and iPad Apps

    This is an excerpt from Manning's book iOS 4 in Action: Developing iPhone and iPad Apps.

    A view is the content holder in your application. You may have several of them, each covering different parts of the window or doing different things at different times. They’re all derived from the UIView class. But don’t think of a view as a blank container. Almost any object you use from UIKit will be a subclass of UIView that features a lot of behavior of its own. Among the major subclasses of UIView are UIControl, which gives you buttons, sliders, and other items with which users may manipulate your program, and UIScrollableView, which gives users access to more text than can appear at once.

    A view controller does what its name suggests. It acts as the controller element of the Model-View-Controller triad and in the process manages a view, sometimes called an application view. As such, it takes care of events and updating for your view.

    So far in the last two chapters we haven’t strayed far from the most fundamental building block of the SDK: the view, whether a UILabel, a UIWebView, or a UIImage-View. Ultimately, the view is only part of the story. As we mentioned when we looked at iOS, views are usually connected to view controllers, which manage events and otherwise take the controller role in the MVC model. We’re now ready to begin a three-part exploration of what that all means.

    A view controller is a UIViewController object that sits immediately above a view (of any sort). It, in turn, sits below some other object as part of the tree that ultimately goes back to an application’s main window. This is shown in figure 5.1.

    Figure 5.1. A bare view controller shows view controlling at its simplest: it sits below one object and above another.

    For this example of table view content creation, you’ll create an NSArray containing an NSDictionary that itself contains color names and UIColor values. As you can probably guess, you’ll fill this skeletal table view example with something like the color selector that you wrote back when you were learning about views in chapter 4. The code required to create your content array is shown in the following listing.

    Listing 5.2. Create the content array
    - (void)viewDidLoad { colorList = [NSArray arrayWithObjects: [NSDictionary dictionaryWithObjectsAndKeys: @"brownColor",@"titleValue", [UIColor brownColor],@"colorValue",nil], [NSDictionary dictionaryWithObjectsAndKeys: @"orangeColor",@"titleValue", [UIColor orangeColor],@"colorValue",nil], [NSDictionary dictionaryWithObjectsAndKeys: @"purpleColor",@"titleValue", [UIColor purpleColor],@"colorValue",nil], [NSDictionary dictionaryWithObjectsAndKeys: @"redColor",@"titleValue", [UIColor redColor],@"colorValue",nil], nil]; [colorList retain]; }

    You should do this sort of setup before the view appears. Here, you do it in the view-DidLoad method. This method is called prior to the view appearing and is a good place to do your initialization.

  • It should control the rotation of its view, which will also require resizing the view in rational ways. Similarly, it should report back on the device’s orientation if queried.
  • iPhone and iPad in Action: Introduction to SDK Development

    This is an excerpt from Manning's book iPhone and iPad in Action: Introduction to SDK Development.

    A view is the content holder in your application. You may have several of them, each covering different parts of the window or doing different things at different times. They’re all derived from the UIView class. But don’t think of a view as a blank container. Almost any object you use from the UIKit will be a subclass of UIView that features a lot of behavior of its own. Among the major subclasses of UIView are UIControl, which gives you buttons, sliders, and other items with which users may manipulate your program, and UIScrollableView, which gives users access to more text than can appear at once.

    A view controller does what its name suggests. It acts as the controller element of the Model-View-Controller triad and in the process manages a view, sometimes called an application view. As such, it takes care of events and updating for your view.

    Ultimately, the view is only part of the story. As we mentioned when we looked at the iPhone OS, views are usually connected to view controllers, which manage events and otherwise take the controller role in the MVC model. We’re now ready to begin a three-part exploration of what that all means.

    A view controller is a UIViewController object that sits immediately above a view (of any sort). It, in turn, sits below some other object as part of the tree that ultimately goes back to an application’s main window. This is shown in figure 5.1.

    Figure 5.1. A bare view controller shows view controlling at its simplest: it sits below one object and above another.

    For this example of table view content creation, you’ll create an NSArray containing an NSDictionary that itself contains color names and UIColor values. As you can probably guess, you’ll fill this skeletal table view example with something like the color selector that you wrote back when you were learning about views in chapter 4. The code required to create your content array is shown here:

    - (void)viewDidLoad {
    colorList = [NSArray arrayWithObjects:
    [NSDictionary dictionaryWithObjectsAndKeys:
    @"brownColor",@"titleValue",
    [UIColor brownColor],@"colorValue",nil],
    [NSDictionary dictionaryWithObjectsAndKeys:
    @"orangeColor",@"titleValue",
    [UIColor orangeColor],@"colorValue",nil],
    [NSDictionary dictionaryWithObjectsAndKeys:
    @"purpleColor",@"titleValue",
    [UIColor purpleColor],@"colorValue",nil],
    [NSDictionary dictionaryWithObjectsAndKeys:
    @"redColor",@"titleValue",
    [UIColor redColor],@"colorValue",nil],
    nil];
    [colorList retain];
    }

    You should do this sort of setup before the view appears. Here, you do it in the viewDidLoad method. This method is called prior to the view appearing and is a good place to do your initialization.

  • It should control the rotation of its view, which will also require resizing the view in rational ways. Similarly, it should report back on the device’s orientation if queried.
  • iPhone in Action: Introduction to Web and SDK Development

    This is an excerpt from Manning's book iPhone in Action: Introduction to Web and SDK Development.

    A web site is iPhone optimized if the web developers have gone all-out to create pages that look great on the iPhone. They’ve probably inserted commands that deal with the iPhone chrome and have thought about iPhone gestures. They may link in unique iPhone style sheets when the device is detected. All of this requires a great understanding of how the iPhone works, but also provides a better experience for users. Many times the view that an iPhone user sees on an iPhone-optimized web site may be dramatically different than that experienced by a desktop user; despite the iPhone’s claim to be a fully featured browser, there are some things that just don’t work as well, and an iPhone-optimized site recognizes that. The slightly more advanced techniques needed to develop iPhone-optimized web sites will also be discussed in chapter 3.

    Ultimately, the view is only part of the story. As we mentioned when we looked at the iPhone OS, views are usually connected to view controllers, which manage events and otherwise take the controller role in the MVC model. We’re now ready to begin a three-part exploration of what that all means.

    Listing 13.1. You can add views to an IB-created view controller inside viewDidLoad
  • It should control the rotation of its view, which will also require resizing the view in rational ways. Similarly, it should report back on the orientation of the iPhone if queried.