[MacOS] Some of the underlying controls

Source: Internet
Author: User

With SB, Ctrl-Drag has auto-generated viewcontroller available, but today we use Xib

Do not tick the use storyboards

This will happen after create:

See, there is no ready-made viewcontroller.

So we need to create our own ~

Do not create xib, because there is already a

Search the object library for Viewcontroller.

Just drag it over here.

Then connect the view to the Xib windows on the right

That's how xib and Rootviewcontroller are linked together.

Add this function in Rootviewcontroller, it will be called when the system loads the Xib (nib is xib after the program is packaged)

And then Ctrl-Drag to drag these, and here's something to watch out for--textview!

We can see that the TextView dragged out of the object library is actually composed of a scrollview and a TextView, TextView is the child control of the ScrollView, so, Want to associate TextView need to select TextView drag on the left, directly drag the associated is scrollview!!!

Complete Rootviewcontroller:

Define two string arrays to hold the option values for the Popupbutton and ComboBox:

var demopop: [String]!var democombo: [string]!

Perfect initialization, in awakefromnib:

Override Func awakefromnib () {        //textfield        demotextfield.stringvalue = "This is a TextField"                //popupbutton        Demopop = ["Pop1", "POP2", "POP3"]        //Clear original item1, item2 demopopupbtn.removeallitems        ()        Demopopupbtn.additemswithtitles (Demopop)        demopopupbtn.selectitematindex (0)                Democombo = ["Combo1", "Combo2 "," Combo3 "]        democombobox.removeallitems ()        democombobox.additemswithobjectvalues (Democombo)        Democombobox.selectitematindex (0)                demodatepicker.datevalue = NSDate ()    }

Note that the Popupbutton add options with the Additemswithtitles, you can also add a additemwithtitles, the same kind of ComboBox.

To define a button click event:

@IBAction func gobtnclicked (sender:anyobject) {let                popupstring = Demopopupbtn.stringvalue        Let textfieldstring = Demotextfield.stringvalue let        combostring = democombobox.stringvalue let        sliderNum = Demoslider.doublevalue let        datestring = demodatepicker.stringvalue                demotextview.string = "U writed" \ ( textfieldstring) ' & Selected ' \ (popupstring) ' in Popupbutton & selected ' \ (combostring) ' in ComboBox & ' \ (slid Ernum) ' in sliders & selected ' \ (datestring) ' in datepicker! '    }

Run to see:

[MacOS] Some of the underlying controls

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.