Set angle radius on UIDatePicker with background color

I have UIDatePickerand I set the background color UIDatePicker:

self.datePicker.backgroundColor = [UIColor lightTextColor];
self.datePicker.layer.cornerRadius = 10;

This successfully puts the background behind UIDatePicker(which in iOS7 is essentially transparent), but does not make rounded corners for the background I'm looking for (I do the same for the image on the screen, and it works fine).
It seems that the angular radius does not affect the background color.
Is there a way to fix this problem by setting the radius of the corner for the background color (or any other solution).

The reason I want to do this is because the regular one UIDatePickerlooks uncomfortable in the view I created, and it looks much better with the background color.
However, all other elements in the view have rounded corners, and I want UIDatePickerthem to fit.

Thanks.

+4
source share
1 answer

You need to add layer.masksToBounds=YES;

Try it,

self.datePicker.backgroundColor = [UIColor lightTextColor];
self.datePicker.layer.cornerRadius = 10;
self.datePicker.layer.masksToBounds=YES;
+10
source

All Articles