Xcode6 New Features

Source: Internet
Author: User

When developing iOS applications, we usually create a large number of custom components to make the interface look beautiful. At present, the graphic Interface development tool Interface Builder in Xcode5 cannot display the Display Effect of custom components. As a result, we have to modify the program process and compile and run it again and again to verify whether the Interface meets the requirements.

In the upcoming Xcode6, Apple provides the instant rendering function of custom components, calledLive Rendering.Live RenderingThis allows us to directly view the visual effects of custom components in Interface Builder, avoiding the need to compile and run the process to verify the results, greatly improving the development efficiency.

Now I will give a brief introduction.Live Rendering. If you want to useLive Rendering, The custom component must be defined in a separate Framework (Xcode6 can now create the Framework for iOS), and the class of the custom component must use@ IBDesignableTo modify the attributes that require dynamic real-time rendering.@ IBInspectable.

Example:

1. Open Xcode6 and create a new project. Select Project templateSingle View ApplicationSelect Swift as the development language.

2. Select a project and create a new one.Target, SelectCocoa Touch FrameworkHere we name the Framework named AFK)

3. In the newly created AFK. framework, we createAFKButtonUser-DefinedUIButtonThe Code is as follows:

 

import UIKit@IBDesignable class AFKButton: UIButton {        @IBInspectable var style:NSInteger  = 0 {    didSet {        switch style {        case 0:            self.backgroundColor = UIColor.blueColor()            self.setTitleColor(UIColor.redColor(), forState:UIControlState.Normal)        case 1:            self.backgroundColor = UIColor.whiteColor()            self.setTitleColor(UIColor.blackColor(), forState:UIControlState.Normal)        default:            self.backgroundColor = UIColor.yellowColor()            self.setTitleColor(UIColor.redColor(), forState:UIControlState.Normal)        }    }    }    /*    // Only override drawRect: if you perform custom drawing.    // An empty implementation adversely affects performance during animation.    override func drawRect(rect: CGRect)    {        // Drawing code    }    */}

 

Here we have added a Live Rendering attribute for AFKButton:StyleIn Interface Builder, modifyStyleYou can see the effect immediately.

4. Open the Main. storyboard generated by the project template and drag a Button to change its Class to AFKButton.User defined Runtime AttributeAdd custom instant rendering attributesStyle, SetTypeSetNumber,Try to modify its value 0, 1, or 2, you can directly see the effect in Interface Builder.

 

Demo project address: https://github.com/Guou/LiveRenderingDemo

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.