iOS7 UITableView做成类似iOS6风格
来源:互联网 发布:爱知时计报价 编辑:程序博客网 时间:2024/05/21 09:06
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://zmhot88.blog.51cto.com/1338337/1358996
1
2
3
4
5
6
7
8
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...........
UIView *testView2 = [[UIView alloc] init];
testView2.backgroundColor = UIColor.clearColor;
cell.selectedBackgroundView = testView2;
......
}
1
2
3
4
5
6
7
8
9
#define IOS7_OR_LATER ( [[[UIDevice currentDevice] systemVersion] compare:@"7.0"] != NSOrderedAscending )
- (
void
)setFrame:(CGRect)frame {
if
(IOS7_OR_LATER) {
NSInteger inset = 10;
frame.origin.x += inset;
frame.size.width -= 2 * inset;
}
[super setFrame:frame];
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
- (
void
)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if
([cell respondsToSelector:@selector(tintColor)]) {
if
(tableView == self.vTableView) {
CGFloat cornerRadius = 10.f;
cell.backgroundColor = UIColor.clearColor;
CAShapeLayer *layer = [[CAShapeLayer alloc] init];
CAShapeLayer *borderLayer = [[CAShapeLayer alloc] init];
CAShapeLayer *selectedLayer = [[CAShapeLayer alloc] init];
CGMutablePathRef borderPathRef = CGPathCreateMutable();
CGRect bounds0 = CGRectInset(cell.bounds, 0, 0);
NSLog(@
"bound0:%@"
,NSStringFromCGRect(cell.frame));
if
(indexPath.row == 0 && indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
CGPathAddRoundedRect(borderPathRef, nil, bounds0, cornerRadius, cornerRadius);
}
else
if
(indexPath.row == 0) {
CGPathMoveToPoint(borderPathRef, nil, CGRectGetMinX(bounds0), CGRectGetMaxY(bounds0));
//left bottom
CGPathAddArcToPoint(borderPathRef, nil, CGRectGetMinX(bounds0), CGRectGetMinY(bounds0), CGRectGetMidX(bounds0), CGRectGetMinY(bounds0), cornerRadius);
CGPathAddArcToPoint(borderPathRef, nil, CGRectGetMaxX(bounds0), CGRectGetMinY(bounds0), CGRectGetMaxX(bounds0), CGRectGetMidY(bounds0), cornerRadius);
CGPathAddLineToPoint(borderPathRef, nil, CGRectGetMaxX(bounds0), CGRectGetMaxY(bounds0));
}
else
if
(indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
CGPathMoveToPoint(borderPathRef, nil, CGRectGetMinX(bounds0), CGRectGetMinY(bounds0));
//left top
CGPathAddArcToPoint(borderPathRef, nil, CGRectGetMinX(bounds0), CGRectGetMaxY(bounds0), CGRectGetMidX(bounds0), CGRectGetMaxY(bounds0), cornerRadius);
CGPathAddArcToPoint(borderPathRef, nil, CGRectGetMaxX(bounds0), CGRectGetMaxY(bounds0), CGRectGetMaxX(bounds0), CGRectGetMidY(bounds0), cornerRadius);
CGPathAddLineToPoint(borderPathRef, nil, CGRectGetMaxX(bounds0), CGRectGetMinY(bounds0));
}
else
{
CGPathAddRect(borderPathRef, nil, CGRectInset(cell.bounds, 0, 1));
}
borderLayer.path = borderPathRef;
CFRelease(borderPathRef);
cornerRadius = 7.f;
CGMutablePathRef pathRef = CGPathCreateMutable();
CGRect bounds = CGRectInset(cell.bounds, 1, 1);
BOOL
addLine = NO;
if
(indexPath.row == 0 && indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
CGPathAddRoundedRect(pathRef, nil, bounds, cornerRadius, cornerRadius);
}
else
if
(indexPath.row == 0) {
CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds0));
CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius);
CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds0));
addLine = YES;
}
else
if
(indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds0));
CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius);
CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds0));
}
else
{
CGPathAddRect(pathRef, nil, CGRectInset(cell.bounds, 1, 0));
addLine = YES;
}
layer.path = pathRef;
selectedLayer.path = pathRef;
CFRelease(pathRef);
layer.fillColor = [UIColor whiteColor].CGColor;
selectedLayer.fillColor = [UIColor redColor].CGColor;
borderLayer.zPosition = 0.0f;
borderLayer.strokeColor = [UIColor blueColor].CGColor;
borderLayer.lineWidth = 1;
borderLayer.lineCap = kCALineCapRound;
borderLayer.lineJoin = kCALineJoinRound;
[borderLayer addSublayer:layer];
if
(addLine == YES) {
CALayer *lineLayer = [[CALayer alloc] init];
CGFloat lineHeight = (1.f / [UIScreen mainScreen].scale);
lineLayer.frame = CGRectMake(CGRectGetMinX(bounds)+1, bounds0.size.height-lineHeight, bounds0.size.width-2, lineHeight);
lineLayer.backgroundColor = tableView.separatorColor.CGColor;
[layer addSublayer:lineLayer];
}
//add general view
UIView *testView = [[UIView alloc] initWithFrame:bounds];
[testView.layer insertSublayer:borderLayer atIndex:0];
testView.backgroundColor = UIColor.clearColor;
cell.backgroundView = testView;
//add selected layer view;
UIView *testView2 = [[UIView alloc] initWithFrame:bounds];
[testView2.layer insertSublayer:selectedLayer atIndex:0];
testView2.backgroundColor = UIColor.clearColor;
cell.selectedBackgroundView = testView2;
}
}
}
0 0
- iOS7 UITableView做成类似iOS6风格
- ios7 tableView 恢复ios6 风格
- UIRefreshControl iOS6 和 iOS7的风格
- 处理ios6到ios7后UITableView的两个显示问题
- ios7的UITableView实现ios6的圆角效果
- iOS7中类似iOS6效果的Grouped TableView
- IOS7学习之路二(处理ios6到ios7后UITableView的两个显示问题)
- UITableView和UISearchBar在ios7和ios6之间的区别【转】
- UITableView和UISearchBar在ios7和ios6之间的区别【转】
- 转)处理ios6到ios7后UITableView的两个显示问题
- (转)处理ios6到ios7后UITableView的两个显示问题
- (转)处理ios6到ios7后UITableView的两个显示问题
- iOS6下修改UISearchBar的输入框背景去除阴影,并设置成iOS7风格
- 模仿IOS里面的UIActionSheet控件,有IOS6和IOS7两种风格
- IOS7、IOS6 UINavigationController遮挡
- iOS6,iOS7适配
- 兼容IOS7和IOS6
- ios6和ios7区别
- CListBox怎样让滚动条终保持在最下方
- 黑马程序员_java基础_函数&数组
- PDF中的box
- java异常【Exception】
- test
- iOS7 UITableView做成类似iOS6风格
- Linux系统下安装中文输入法 fcitx
- 非技术书籍收集
- 黑马程序员学习笔记——关于时间复杂度计算1
- 如何让ImageView的背景图片不缩放
- Web后台开发中的-复制功能
- SSD纠错码向LDPC码演变
- CCeSocket
- vector 反向迭代器的使用