Tar*_*era 17 objective-c uitableview ios
我想像我的iOS应用程序中的图像一样给出类似卡片的阴影效果
我在UITableViewCell上需要这个图像对我来说也不适用于具有阴影效果的单元格之间的间隙
Has*_*ain 14
在表格视图单元格中使用容器视图并指定标记99.保持单元格高度比卡片(容器视图)大一些.
并为您的卡片视图提供阴影
UIView* shadowView = [cell viewWithTag:99];
shadowView.backgroundColor=[UIColor colorWithRed:228.0/255.0 green:228.0/255.0 blue:228.0/255.0 alpha:0.5];
[shadowView.layer setCornerRadius:5.0f];
[shadowView.layer setBorderColor:[UIColor lightGrayColor].CGColor];
[shadowView.layer setBorderWidth:0.2f];
[shadowView.layer setShadowColor:[UIColor colorWithRed:225.0/255.0 green:228.0/255.0 blue:228.0/255.0 alpha:1.0].CGColor];
[shadowView.layer setShadowOpacity:1.0];
[shadowView.layer setShadowRadius:5.0];
[shadowView.layer setShadowOffset:CGSizeMake(5.0f, 5.0f)];
Run Code Online (Sandbox Code Playgroud)
关于swift 3.0的即兴解决方案:
extension UIView {
func setCardView(){
layer.cornerRadius = 5.0
layer.borderColor = UIColor.clear.cgColor
layer.borderWidth = 5.0
layer.shadowOpacity = 0.5
layer.shadowColor = UIColor.lightGray.cgColor
layer.shadowRadius = 5.0
layer.shadowOffset = CGSize(width:5, height: 5)
layer.masksToBounds = true
}
}
Run Code Online (Sandbox Code Playgroud)
用法:
在cellForRowAt indexPath上:
var cell = UITableViewCell()
cell.contentView.setCardView()
Run Code Online (Sandbox Code Playgroud)