手机类毕业设计外文翻译内容摘要:

riting code directly in . . Add a Cocoa UILabel in Interface Builder to . . Define a subclass of UIView, and use a Quartz font rendering in drawRect. . Create a texturemapped font in OpenGL ES to render with. Let’s start with the first method: adding a UILabel by writing code in HelloWorldView . A stub method named viewDidLoad is already inside HelloWorldView , which is a good place to add our code. This method will be called after .nib file loading is done, but before rendering begins: 第 8 页 共 66 页 1. Replace the viewDidLoad function in with the following (this function is mented out by default, so be sure to remove the /* that precedes it and the */ that follows it): (void) viewDidLoad { [super viewDidLoad]。 //draw Hello World using Cocoa UIKit. //grab the screen dimensions int w =。 int h =。 //create a text label: the size 100,50 here is arbitrary // but it must be large enough to fit the Hello World text. UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 50)]。 //put the label at the center of the screen = CGPointMake(w/2, h/2)。 //align the text to the center of the label (default is left) = UITextAlignmentCenter。 //don39。 t draw the label39。 s background (default is white) = [UIColor clearColor]。 = @Hello world!。 //add label to our view, so that it can be rendered [ addSubview:label]。 //since we alloc39。 d label in this method we need to release label here [label release]。 } 2. Build and run the project (if you haven’t quit the Simulator from its previous run, you’ll be prompted to stop it). The app should now display your text (see Figure 13). 第 9 页 共 66 页 Figure 13. “Hello world!” text shown Now let’s go over the second method, adding a UILabel to HelloWorldViewController. xib using Interface Builder. You must undo your changes if you followed the preceding example: 1. Open the file in Interface Builder by doubleclicking it from the list of project files in Xcode. 2. Doubleclick the View object to begin editing it (Figure 14). Figure 14. Doubleclicking the View object to edit the file 3. Find the Label object in the Library panel (open the panel by selecting Tools 仺 Library Panel, if it is not already open). See Figure 15. 4. Drag the label into the View editing window, as shown in Figure 16. 5. Doubleclick the new label and edit the text to say “Hello World”. You can also edit it from the Attributes Inspector (Tools 仺 Attributes Inspector). 第 10 页 共 66 页 6. In the Label Size Inspector (Tools Size Inspector), click both of the Placement buttons to center the label horizontally and vertically, as shown in Figure 17. 7. Save the .xib file and return to Xcode. Building the application will update the .nib file, which will cause the changes to appear when the application is run, as shown in Figure 18. 8. When the .nib file is loaded, it creates and displays the UILabel. If our code needs access to read or modify the created label, we can link it to an IBOutlet in our code. In , replace the stub definition of HelloWorldViewCon troller with the following: @interface HelloWorldViewController : UIViewController { IBOutlet UILabel* myLabel。 } An IBOutlet is a code tag that enables Interface Builder to recognize possible handles in code that can be linked to. 第 11 页 共 66 页 Figure 15. Selecting Label from the Objects Library 9. To link the .nib’s label to the outlet, open in Interface Builder and open the Connections Inspector (Tools Connections Inspector). Then, click to select the label, drag the label’s New Referencing Outlet to the File’s Owner object, release, and click on the “myLabel” text that shows up in the Apple Developer Account and Downloading the SDK | 9 Download at popup menu (see Figures 19 through 111). Because we set the Referencing Outlet, the two objects will be linked together when the .nib is loaded. Specifically, when is loaded in the application, it will know to set the variable myLabel to point at the UILabel we just linked to. 10. Save and quit Interface Builder. 第 12 页 共 66 页 Now our code has access to the label through myLabel. This linking process is used frequently in Interface Builder to specify outlets, actions, delegates, and data sources. Any interaction between visible elements of the interface and your code is made via Interface Builder links. Figure 16. Adding a new label to the view 第 13 页 共 66 页 Figure 17. Modifying the Label object properties Figure 18. “Hello World!” text with Label object Figure 19. The Label Connections window 第 14 页 共 66 页 Figure 110. Clicking and dragging from New Referencing Outlet to File’s Owner Views and Controllers The UIView class represents a View object in the iPhone SDK. Views are visible rectangular portions of the screen that handle drawing and animation, event handling, and subview management. If you look at the iPod application that es with your iPhone, you’ll see that the navigation bar at the top, the tab bar at the bottom, and the content area in the middle are three separate views. When creating a viewbased application in the New Project Wizard, start with a single View Controller and a single View. You may want more Views as your application bees more plex. For example, you may have one View for your game, another for a Main menu, one for a Settings screen, and another for an online High Score screen. If your Views share a lot of the same code, it makes sense to add those Views to the same View Controller, along with the shared code. In the preceding example, we may want to put the Main menu and the Settings in the same View Controller, but put the main Game state and High Score screen each in their own View Controller. Nothing is stopping us from putting。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。