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