Developing Mac Apps with Swift (4)

Source: Internet
Author: User

Create a detail page

In iOS, a typical "master-thin page app" needs to create two views, but in OS X we can combine them in the same view because the screens are no longer restricted.

Open masterviewcontroller.xib, select View, and drag the width and height to the top.


We need to display the following information: Insect name, thriller index and insect picture.

The insect name is displayed with the Nstextfield control, and the horror index is displayed with the edstarrating control, and the insect picture is displayed with Nsimageview .

In addition, we need two labels to represent the meaning (title) of each field.

Drag a Text field (insect name), 2 labels (field header), an image view into view.

The edstarrating control is a custom control that cannot be found in the objects library, so you need to drag a custom View control first.

Place the controls on the right side of the view, from top to bottom:

· The first is a label, which serves as the field title for the insect name, and below it is the TextField.

· Below the text field is the second label (the field title of the thriller Index).

· At this label, Below is a customview (which is later changed to the Edstarrating control).

· The bottom is the image view below control.

All controls are aligned to the left, as shown in:


Then select the custom View control and open the Identity panel (the Third tab button) to change the class to edstarrating.


Select the first label, open the Attributes Panel (4th tab button), and modify the title to "name".

According to the method above, change the title of the second label to "Rating".

Select the top-level view (displayed as "Custom view" in the Document Outline panel), open the size panel and see its sizes:


Open mainmenu.xib, select Scarybugsmac window, set window's width height to the width that you remembered earlier. Then tick minimumsize .


The post-operation effect is as follows:


The edstarrating control is not displayed on the interface because we have not configured it yet.

Open masterviewcontroller.xib, open the Assistant editor (the second button in the Editor panel of the toolbar), and make sure that the current edits are Masterviewcontroller.swift.

With the table View selected, press the right button and drag a line to the masterviewcontroller.swift file:


This will pop up a window that allows you to create a iboutlet. Enter Bugstableviewin name, Storage set to Weak, then click Connect.


Repeat the steps above to create two Iboutlet for text field and image view:

Bugtitleview,bugimageview.

For custom view, create a iboutlet: bugrating.

Finally, the following additions will be added to the masterviewcontroller.swift file:

@IBOutlet weak var bugstableview: nstableview!

@IBOutlet weak var bugtitleview: nstextfield!

@IBOutlet weak var bugimageview: nsimageview!

@IBOutlet weak var bugrating: edstarrating!


Developing Mac Apps with Swift (4)

Related Article

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.