Character to class in Swift programming, code creation control in detail

Source: Internet
Author: User

in the Swift Programming (http://www.maiziedu.com/course/ios/16-161/) , we all encounter these two questions, how to turn characters into classes and code to create a control method, the following specific explanation of these two points of knowledge  

Get the namespace before you use the class

Using JSON to get the class name of the character type and then create the class object, it is necessary to use the character to turn class

Gets the namespace from the info Dictionary to the character type

Let NS = Nsbundle.mainbundle (). infodictionary! ["Cfbundleexecutable"] as! String

Let Clss:anyclass? = nsclassformstring (NS + ".") + character class name )

Let Vcla = Clas as! Uiviewcontroller.type//Convert the class type to the appropriate type

Let VC = Vcla.init ()// Initialize an object

modifying namespaces

Creating controls

Way: Code creation,xib creation,nib creation

It is generally necessary to rewrite the init to add the corresponding property or the corresponding object

in SWITF  init

    required init? (Coder adecoder: nscoder)  {
        fatalerror ("Init (coder:)  has not been  Implemented ")
    }

This init is limited by the code that we can only create controls to prevent confusion

Calculates another control formula based on one control

What property of that control is equal to what property of another control multiplied by how much ?

let masswidth =  Nslayoutconstraint (Item:  control 1,  attribute:  control 1 () multiples how much   )

to set the width of a control

AddConstraint (Masswidth)


Character to class in Swift programming, code creation control in detail

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.