向 UIView 添加阴影
Adding Shadows to UIViews
这几天我一直在断断续续地研究如何正确地向 UIView 添加阴影。关于该主题的资源很多,但 none 到目前为止对我有用。影子没有出现。
cell.buttonView.layer.shadowColor = UIColor.blackColor().CGColor
cell.buttonView.layer.shadowOffset = CGSizeMake(4, 4)
cell.buttonView.layer.shadowRadius = 5
cell.buttonView.layer.shadowOpacity = 1.0
cell.buttonView.layer.masksToBounds = false
更改 masksToBounds 是因为在另一个人的代码中缺少该步骤似乎是他们无法让阴影出现的原因。
您的代码很好(并且有效,刚刚试过)。问题一定出在其他地方。
请注意,仅当您的视图有内容时才会应用阴影。因此,如果您的视图 backgroundColor
是 clearColor
,则它不会显示阴影。
还要检查您的代码 运行 并且仅在某些情况下不运行 ;)
这几天我一直在断断续续地研究如何正确地向 UIView 添加阴影。关于该主题的资源很多,但 none 到目前为止对我有用。影子没有出现。
cell.buttonView.layer.shadowColor = UIColor.blackColor().CGColor
cell.buttonView.layer.shadowOffset = CGSizeMake(4, 4)
cell.buttonView.layer.shadowRadius = 5
cell.buttonView.layer.shadowOpacity = 1.0
cell.buttonView.layer.masksToBounds = false
更改 masksToBounds 是因为在另一个人的代码中缺少该步骤似乎是他们无法让阴影出现的原因。
您的代码很好(并且有效,刚刚试过)。问题一定出在其他地方。
请注意,仅当您的视图有内容时才会应用阴影。因此,如果您的视图 backgroundColor
是 clearColor
,则它不会显示阴影。
还要检查您的代码 运行 并且仅在某些情况下不运行 ;)