如何更改UITableView中每個單元格末尾出現的分隔線? 我想要一個圖像,這是一個薄型分隔線類型的線條圖像。UITableView分隔線
回答
您可以添加一個UIImageView,例如,單元格的高度和寬度一樣寬,然後將其原點設置爲單元格的左下角。
將tableview的separatorStyle
設置爲UITableViewCellSeparatorStyleNone
。將您的分隔符圖像作爲子視圖添加到每個單元格並正確設置框架。
你會plz給我一個例子。 – 2011-01-26 12:46:18
[separatorImageView setFrame:CGRectMake(0,0,cell.frame.size.width,separatorImageView.image.size.height)]; – Felix 2011-01-26 12:54:43
[cell.imageView setFrame:CGRectMake(0,0,cell.frame.size.width,cell.frame.size.height)];沒有能夠做到這一點:( – cV2 2011-03-16 14:40:33
如果要更改默認選項(無分隔符,實線或蝕刻線),您有2個選項可更改uitableview的分隔符樣式。
最簡單的由在包括分隔線背景圖像 給每個小區視圖。你可以檢查你的單元格位於 tableview的哪個位置,以便應用正確的背景圖像,該背景圖像將爲您提供 單元格頂部的分隔線或 單元格的底部。
設置分隔符的風格沒有你 的tableview的viewDidLoad中:
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone]。
設置你的背景圖像中(的UITableViewCell *)的tableView:(UITableView的*)的tableView 的cellForRowAtIndexPath:(NSIndexPath *)indexPath功能
UIImage* yourBgImg = [[UIImage imageNamed:@"bgImage.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
cell.backgroundView = [[UIImageView的頁頭] initWithImage:yourBgImg];
檢查你的細胞的結合下面的部分中的位置:
NSInteger的sectionRows = [的tableView numberOfRowsInSection:[indexPathsection]]; NSInteger row = [indexPath row];
- 將分隔線添加爲單元格。我發現一個帖子最近這 這裏: http://www.dimzzy.com/blog/2012/01/separator-cells-for-uitableview/#disqus_thread
試試這個:
UIImageView *separator = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"separator.png"]];
[cell.contentView addSubview: separator];
這就是我如何得到它工作得很好的例子。
請記住將表視圖的分隔符樣式設置爲無。
首先,你可以寫代碼:
{ [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];}
後
{ #define cellHeight 80 // You can change according to your req.<br>
#define cellWidth 320 // You can change according to your req.<br>
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"seprater_line.png"]];
imgView.frame = CGRectMake(0, cellHeight, cellWidth, 1);
[customCell.contentView addSubview:imgView];
return customCell;
}
}
試試這個
目標C
[TableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
[TableView setSeparatorColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"[email protected]"]]];
斯威夫特
tableView.separatorStyle = UITableViewCellSeparatorStyle.SingleLine
tableView.separatorColor = UIColor(patternImage: UIImage(named: "YOUR_IMAGE_NAME")!)
設置分隔符的顏色與你的圖像進行構圖。
在viewDidLoad
:
self.tableView.separatorColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"mySeparatorImage"]];
這裏是通過使CALayer
用於圖像,並使用該添加自定義分隔線到UITableView
的另一種方法爲分隔線。
//作出的CALayer爲分隔線的圖像
CALayer *separator = [CALayer layer];
separator.contents = (id)[UIImage imageNamed:@"myImage.png"].CGImage;
separator.frame = CGRectMake(0, 54, self.view.frame.size.width, 2);
[cell.layer addSublayer:separator];
我的項目是基於iOS上的7 這有助於我
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
然後把一個子視圖到小區分隔器!
你可以試試下面:
UIView *separator = [[UIView alloc] initWithFrame:CGRectMake(0, cell.contentView.frame.size.height - 1.0, cell.contentView.frame.size.width, 1)];
separator.backgroundColor = myColor;
[cell.contentView addSubview:separator];
或
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"separator.png"]];
imageView.frame = CGRectMake(0, 100, 320, 1);
[customCell.contentView addSubview:imageView];
return customCell;
}
這是絕對有幫助。加工。 ,但從屬性檢查器中設置分隔符「無」。在的cellForRowAtIndexPath 寫下面的代碼方法
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0,
cell.contentView.frame.size.height - 1.0,
cell.contentView.frame.size.width, 1)];
lineView.backgroundColor = [UIColor blackColor];
[cell.contentView addSubview:lineView];
斯威夫特3/4
自定義的分隔線,把這個代碼在這的UITableViewCell的子類中的自定義單元格(或CellForRow或WillDisplay TableViewDelegates爲非定製單元格):
let separatorLine = UIImageView.init(frame: CGRect(x: 8, y: 64, width: cell.frame.width - 16, height: 2))
separatorLine.backgroundColor = .blue
addSubview(separatorLine)
在每個tableview單元格下添加分隔線的最簡單方法可以在t他故事板本身。 首先選擇tableview,然後在屬性檢查器中選擇分隔線屬性爲單行。之後,選擇要自定義的分隔符插入,並將左側插入從左側更新爲0。
- 1. UItableview分隔線的高度
- 2. UITableView上的分隔線
- 3. 創建自定義的UITableView分隔線
- 4. 由虛線分隔的UITableView單元格
- 5. 的iOS的UITableView隱藏分隔線
- 6. UITableView分隔線樣式「單線蝕刻」不能正常工作
- 7. 母分隔線之外的分隔線
- 8. UITableView分隔符問題
- 9. UITableView中的分隔單元
- 10. 消除uitableview tablefooterview分隔符
- 11. Grid +分隔線
- 12. 刪除分組UITableView中的分隔符
- 13. 有沒有辦法從UITableView中刪除分隔線?
- 14. 靜態UITableView顯示分隔線時,他們已被禁用
- 15. UITableView編輯配件視圖分隔線顏色
- 16. Xamarin.iOS UITableView以編程方式隱藏分隔線
- 17. 動態更改UITableView單元格分隔線顏色
- 18. UITableViewCellSeparatorStyleNone在UITableView中選擇時不隱藏藍色分隔線
- 19. 有沒有辦法自定義UITableView的分隔線圖形?
- 20. 在UITableView中設置分隔線的開始?
- 21. UITableView分隔線在滾動單元格之間消失
- 22. 顯示分隔線
- 23. UISegmentedControl分隔線bug
- 24. Android:GridLayout的分隔線
- 25. 添加分隔線
- 26. Android ListView分隔線
- 27. TableView部分分隔線
- 28. 如何添加自定義UITableView標題部分筆尖的分隔線?
- 29. iPhone + UITableView +爲分隔符設置圖像
- 30. UITableView分隔符在錯誤的位置
不要忘記關閉默認的分隔樣式表視圖:`[自我。tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];` – Jasarien 2011-01-26 12:41:04
你可以給我粗略的代碼,所以我可以開始,我如何設置它的起源單元格的左下角? – 2011-01-26 12:43:44
我已經得到了解決方案,謝謝大家。 – 2011-01-26 13:25:32