使用背景颜色在UIDatePicker上设置角半径 [英] Setting corner radius on UIDatePicker with a background color

查看:148
本文介绍了使用背景颜色在UIDatePicker上设置角半径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的视图中有一个 UIDatePicker ,并设置了 UIDatePicker 的背景颜色:

I have a UIDatePicker in my view and have set the background color of the UIDatePicker:

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

这成功地将背景置于 UIDatePicker 之后(在iOS7中基本上是透明的)但是无法为我正在寻找的背景制作圆角(我为屏幕上的图像做同样的事情并且它完美地工作)。$
似乎角半径不会影响背景颜色。

有没有办法通过设置背景颜色的角半径来解决这个问题(或任何其他解决方案)。

This successfully puts a background behind the UIDatePicker (which in iOS7 is essentially transparent) but fails to make the rounded corners for the background that I am looking for (I do this same thing for an image on the screen and it works perfectly).
It seems that the corner radius doesn't affect the background color.
Is there a way to fix this problem by setting a corner radius for the background color (or any another solution).

我想这样做的原因是因为普通的 UIDatePicker 看起来很尴尬我构建的视图和背景颜色看起来好多了。

但是,视图中的所有其他项目都有圆角,我想要 UIDatePicker 匹配他们。

The reason I want to do this is because the ordinary UIDatePicker looks awkward in the view I have constructed and looks much better with a background color.
However, all the other items in the view have rounded corners and I want the UIDatePicker to match them.

谢谢。

推荐答案

你必须添加 layer.masksToBounds = YES;

试试这个,

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

这篇关于使用背景颜色在UIDatePicker上设置角半径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆