iOS Development Series-Interface

Source: Internet
Author: User

In this chapter, we design a simple login interface to explain how to design the interface in iOS. After opening the project created in the previous chapter, we will first import several images that need to be used. The import method is actually very simple. Select Assets.xcassets. Then drag the picture you use into it. Here is the name of the picture is best to bring a page in front of what, because although you can create a folder in the Assets.xcassets, but the final time to read the picture is no path, that is, if you have the same name in different folders of the picture file will be problematic. Speaking of picture files. It is recommended to find a Web site http://www.easyicon.net for image resources. This image site is more intimate, there are two points. 1: Yes will speak your Chinese search keywords automatically turn into English. 2: A variety of pixel formats are available for each image. The General landing page contains these elements: System logo, username input box, password input box, and login button. So let's find a cool logo first. I take the Weixin logo to use it. In addition, the PNG files are optimized for compression when Xcode is compiled. So choose PNG images as much as possible. The screen width of the iphone is about 320px, so the size of the logo I chose is 128*128. Download the name after you drag it into the project. You'll find a 2x,3x. What is this for? This involves Apple's design approach, and his goal is to expect a set of code to match all the devices. So 1x is used for ordinary iphone,2x for plus,3x for ipad. Unfortunately, the ipad version has been used to know ...

When the resource files are ready, we begin to formally design the interface and select the Main.storyboard file. interface such as. Inside the Viewcontrol.control you can understand is our ASPX file, which is the container for our interface. There is a view in it. You can understand the equivalent of a div. The left is a list of all control, showing his hierarchy and what it contains. In the middle is the graphical interface of our editing app page. On the right is the controller or the control's property settings, and the lower right corner is the one you can use.

First we drag a imageview to load the logo. You can quickly navigate through the search bar at the bottom of the bottom control area. Then set its Image property. Here is a description, if you forget the name of the picture. You can click the 4th preview in the lower right corner of the ribbon, such as

Then drag into the two TextField. One of them sets its placeholder (the input prompt in the input box) as the user name. Another setting of its placeholder is the password. And hook on the secure Text entry settings to ensure that the input password is not visible. Such as

Finally, drag a button and set its Title property to login. So all the elements of our interface are ready. The next step is the layout. The default layout in Xcode is that you need to provide 4 values, that is, the x, y coordinates of the point where the upper-left corner of your control is located and the width and height of the control itself. Such as

This can be used in the early days to meet development needs. But because of the size of the iphone's screen now there are many. Writing directly to death is obviously a problem. Of course you can also calculate dynamically in the code. But obviously not too intuitive, debugging up also inconvenient. Fortunately, the official launch of the AutoLayout, that is, automatic layout. The main idea is two kinds. One is to specify the relative distance and height of the left and right neighboring elements of the control, and then to adapt the width to the screen, and to specify the width of the control and the relative distance of neighboring pixels of the adjacent element, and then set the control to automatically center horizontally. Do both of these methods sound familiar? This is actually the Web page to deal with the different resolutions of the screen, the principle is clear, let us start the specific operation.

First select our ImageView. Because the aspect ratio of the picture is fixed, it is not possible to adapt the width of the image, otherwise the picture will deform. So we use the second way, to make the picture fixed long and wide and then centered. Here, by the way, the iphone series phone's screen has a visible width greater than or equal to 320px. After we select ImageView, click the third button below the middle. Set the ImageView distance above 8px (note to first select the corresponding red line). Width is 240px. The height is 120px. Then click Add 3 Constraints (that is, add the 3 constraints we set).

Then select the 2nd button at the bottom. Tick horizontally in container (horizontal center)

Then select the User Name entry box. We use the first approach, such as

Next we set the password and login button in a similar way. You'll find out when you're done. There is a yellow arrow on the left-hand list.

Click. He will show you the constraints of several controls and the effect you actually display inconsistent, it doesn't matter, click the past to select Updateframes can

After refreshing the interface effect as

Next, let's look at the effect of the operation. There are two ways to debug, one is to use an emulator and one is to debug with a real machine. If you have the conditions, try to use the real machine as much as possible. Let's talk about how to use the simulator first. For example, select the simulator model and click Run.

Running effect

In addition, the default width of the simulator is ugly, unlike the phone effect, it is recommended to adjust the proportion. Adjust the way as. Select the simulator, then click Window to set the corresponding scale

About the real-machine debugging, previously because of the need for developer certificates or more cumbersome, xcode7 version after a lot of simplification, the specific way see this tutorial http://www.skyfox.org/ios-xcode7-debug-device.html. Okay, here's the chapter.

iOS Development Series-Interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.