这是我设计的清单项目。列表中有多个项目,例如tableview 只是有一个矩形项目,它的边框很细,外面有阴影。
节标题,说明和主管是该节中单元格的数量。
我已经尝试过这段代码。
-(void)drawLeftBorder : (UIView *)view{
CALayer *leftBorder = [CALayer layer];
leftBorder.backgroundColor = [UIColor colorWithRed:221/255.0f green:221/255.0f blue:221/255.0f alpha:1].CGColor;
leftBorder.frame = CGRectMake(0,0,1,view.frame.size.height+1);
leftBorder.shadowColor = [UIColor grayColor].CGColor;
leftBorder.shadowOffset = CGSizeMake(0, 0);
leftBorder.shadowOpacity = 1;
leftBorder.shadowRadius = 5;
[view.layer addSublayer:leftBorder];
}
-(void)drawRightBorder : (UIView *)view{
CALayer *rightBorder = [CALayer layer];
rightBorder.backgroundColor = [UIColor colorWithRed:221/255.0f green:221/255.0f blue:221/255.0f alpha:1].CGColor;
rightBorder.frame = CGRectMake(view.frame.size.width-1,0,1,view.frame.size.height+1);
rightBorder.shadowColor = [UIColor grayColor].CGColor;
rightBorder.shadowOffset = CGSizeMake(0, 3);
rightBorder.shadowOpacity = 1;
rightBorder.shadowRadius = 5;
[view.layer addSublayer:rightBorder];
}
-(void)drawTopBorder : (UIView *)view{
CALayer *topBorder = [CALayer layer];
topBorder.backgroundColor = [UIColor colorWithRed:221/255.0f green:221/255.0f blue:221/255.0f alpha:1.0f].CGColor;
topBorder.frame = CGRectMake(0,0,view.frame.size.width,1.0);
topBorder.shadowColor = [UIColor grayColor].CGColor;
//topBorder.shadowColor = [UIColor grayColor].CGColor;
topBorder.shadowOffset = CGSizeMake(0, 0);
topBorder.shadowOpacity = 1;
topBorder.shadowRadius = 5;
[view.layer addSublayer:topBorder];
}
答案 0 :(得分:0)
无需使用CALayer或CAShape图层,因为我们可以直接操纵该部分的图层以显示边界和阴影。
UITableViewHeaderFooterView *section = [tblView
dequeueReusableHeaderFooterViewWithIdentifier: @"identifier"];
[section.layer setMasksToBounds: false];
[[UIColor grayColor] CGColor];
//Adding border to your section
[section.layer setBorderWidth: 1.0]; //Change Border Width here
[section.layer setBorderColor: [[UIColor grayColor] CGColor]]; //Change Border Color here
//Adding shadow to the section
[section.layer setShadowColor: [[UIColor darkGrayColor] CGColor]]; //Change Shadow Color here
[section.layer setShadowOffset: CGSizeZero]; //Change Shadow Offset i.e shadow's displacement from section
[section.layer setShadowRadius: 3.5]; //Change Shadow Radius i.e how far the shadow will spread
[section.layer setShadowOpacity: 0.50]; //Change visibility of shadow here