Let's take a look at the rounded corners of a button, as shown in the following code:
Button.layer.masksToBounds =yes;
Button.layer.cornerRadius = 10;
To implement a button's shadow effect, the following code:
Button.shadowoffset = Cgsizemake (10, 10);
button.shadowopacity = 0.7;
At this point, if you want to realize the fillet and shadow effect, then there will be a problem, you set the maskstobounds to Yes at this point is rounded, but the shadow will be gone, you set it to No, the fillet is gone, the shadow has, so I began to full network to check, have not found a solution, Finally, in a forum, a brother said: need to use a layer to achieve the shadow, and then I follow this line of thought, wrote the following code
Calayer *layer = [Calayerlayer];
Layer.frame = CGRectMake (in the same position as the button and the same size);
Layer.backgroundcolor = [Uicolorblackcolor]. Cgcolor;
Layer.shadowoffset = Cgsizemake (10, 10);
layer.shadowopacity = 0.7;
Layer.cornerradius = 10;
Here, self represents the currently customized view
[Self.layeraddSublayer:layer];
UIButton *button = [[Uibuttonalloc]initwithframe:cgrectmake (a certain size of position)];
[Self Addsubview:button];
Button.layer.masksToBounds =yes;
Button.layer.cornerRadius = 10;
Results: At the same time to achieve the fillet and shadow, the idea is to add a layer between the button and the view, to achieve a fillet with a shadow, so that the final effect can be achieved, note must first upper button, so that the button on the layer.
Reprinted from: http://blog.csdn.net/jnbbwyth/article/details/50899611
The iOS button also enables rounded and shaded effects