Ios:uiview's Calayer Basic walkthrough

Source: Internet
Author: User

UIView Properties and considerations for the Calayer Basic Walkthrough:Create a button UIButton in UIView and set the Layer property of the UIButton– Fillet, Border, shadow, and 3D deformation propertiesNote:1. Calayer is just a class declaration in UIView, so you need to add a Quartzcore framework (iOS7 is no longer required to import)The 2.UIKit framework can only be applied to iOS and not to Mac, but quartz 2D is cross-platform, so when using colors, you cannot use Uicolor directly and you need to turn colors into Cgcolor3. Modify the layer equivalent to modify the UIView property, that is, modify the interface properties4. Deformation properties can be specified either by a deformation function or by KeyPath The specific code demonstrates the following: All the code is in the controller class-(void) viewdidload {[Super Viewdidload]; ...} method to complete the//Create button
    // Add button    UIButton *button = [[UIButton alloc]init];     // Set Frame    Button.frame = CGRectMake (+);

//Background color

Button.layer.backgroundColor = [[Uicolor Redcolor]cgcolor];

[Self.view Addsubview:button];

Demo Results

Set rounded corners

    // set the fillet radius    50.0;

Demo Results

Set Border

    // set border (color, siding)    Button.layer.borderColor = [[Uicolor Greencolor]cgcolor];     2.0;

Demo Results

Set Shadow

    // Set the shadow (color, offset, transparency, radius)    Button.layer.shadowColor = [[Uicolor Purplecolor]cgcolor];     = Cgsizemake (00);     1.0 ;     20.0;

Demo Results

Add Content

    // Set Content    Button.layer.contents = (ID) [[UIImage imagenamed:@ "2.png"] cgimage];

Demo Results

// translational Deformation and restitution (demo results self-validating)
    // set panning (translation length per axis)    Button.layer.transform = catransform3dmaketranslation (0.0);     // Resume Panning    //button.layer.transform = catransform3didentity;

// perform optional deformation and restore status
    // set Rotation (rotation angle, x-axis, y-axis, z-axis)    1 0 0 );     // Resume Rotation    //button.layer.transform = catransform3didentity;

Demo Results

to be retracted and restored to its original state.

    // Set the indent (scale factor for each axis direction)    Button.layer.transform = Catransform3dmakescale (222);     // Restore Shrink    //button.layer.transform = catransform3didentity;

Demo results

Ios:uiview's Calayer Basic walkthrough

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.