2013-07-20 126 views
3

有人請解釋如何僅在最後一個單元格上創建一個或兩個像素陰影(換句話說,我不想在整個tableview中使用陰影,只是在底部單元格什麼我談論的圖像:爲UITableView創建陰影

enter image description here

回答

2

解決。使用下面的代碼在的底部產生一個非常漂亮的微妙陰影3210。使它看起來像它微微擡起了頁面:)

UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(3, 49, cell.frame.size.width-26, 3)];/// change size as you need. 
     separatorLineView.backgroundColor = shadowColor;// you can also put image here 
     UIBezierPath *roundedShadow = [UIBezierPath bezierPathWithRoundedRect:separatorLineView.bounds byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight cornerRadii:CGSizeMake(8.0f, 8.0f)]; 
     CAShapeLayer *newSeparatorShape = [[CAShapeLayer alloc] init]; 
     [newSeparatorShape setPath:roundedShadow.CGPath]; 

     separatorLineView.layer.mask = newSeparatorShape; 

     [cell.contentView addSubview:separatorLineView]; 

而且,不要忘了把這個在您的.m文件#import <QuartzCore/QuartzCore.h>

+1

我也試着用這個貝塞爾路徑:) – KDeogharkar

+1

@BaZinga好男人,好:] – Apollo

+0

@BaZinga是的,現在,當你選擇它使用你在最後一個問題的答案中描述的高亮技術時,陰影是失去了,所以只用貝塞爾路徑來實現它可能會解決這個問題...... – Apollo

0

,你可以在的tableView:cellForIndexPath:細胞的背景圖片設置爲一個包括與陰影的圓角

+0

的頂部是真正的最佳方式,但?有沒有辦法與原生圖形框架做到這一點? – Apollo