iOS project development--use XCODE6 to design custom controls and graphics

Source: Internet
Author: User
Tags border color

In iOS development, there are many controls that are provided by Xcode by default. It is very convenient to use these controls. But for some needs, you need to design your own controls, so what should you do? This interface is provided in Xcode6, allowing developers to quickly develop custom controls and provide real-time preview functionality. The specific implementation steps are as follows:

(1) Create a single View Application,language select Swift. Then click on the project name in the System Configuration main screen and select Add Target.

.


.


(2) then select the Cocoa Touch Framework in the popup dialog box and enter the name. The project name I entered is customviews.


(3) After the above Cocoa Touch framework has been created, there are two more folders under the project directory, and now the directory structure is as follows:


(3) Create a new cocoa Touch Class in CustomViews. Language Select Swift, class name arbitrarily take, note subclass of To select UIView, click Create. A swift class is then generated.


(4) First drag into a view control in the Main.storyboard, you can set a background color, and so on. Wait a moment to use the Swift class to customize the view control. Note that this is a view control.


(5) Then on the right side of the control select Indentity Inspector in the class to enter the Swift class just created, I entered the myviews, and then the system by default will also fill in the module.


(6) Then we can go to Myviews.swift to customize the controls. Write the following code: first declare the class as @ibdesignable, which means it can be redesigned.

Import Uikit@ibdesignable class Myviews:uiview {    //Border width;    @IBInspectable var borderwidth:cgfloat = 0{            didset{                    layer.borderwidth = BorderWidth        }    }        //Border color;    @IBInspectable var bordercolor:uicolor = Uicolor.clearcolor () {            didset{                    layer.bordercolor = Bordercolor.cgcolor        }    }        /fillet radius;    ibinspectable var cornerradius:cgfloat = 0{            didset{                    Layer.cornerradius = Cornerradius        }    }        / /background color;    @IBInspectable var backgroundcolors:uicolor = Uicolor.clearcolor () {            didset{                    Layer.backgroundcolor = Backgroundcolors.cgcolor        }}}    

(7) then come to Main.storyboard, select the view control just now, found that there are several options for setting properties on the right side, namely setting the border width, border color, fillet radius and background color,


By changing the properties, you can implement viewing the current design results in the interface:


With the above steps, we can design our favorite control effects at will.









Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

iOS project development--use XCODE6 to design custom controls and graphics

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.