Is there any way to modify a UITableView's separator cell?

一个人想着一个人 提交于 2019-12-22 01:31:41

问题


My app will be using slightly thicker separator lines in tableViews - about 3x the thickness. I have already done this in some areas by setting separatorStyle to none and customizing cell backgroundViews with custom backgrounds that include my thick separator.

The issue with this method is that it only applies to real rows. Thus if I have a tableView that fills the whole screen but only has two rows, then only the two rows will have the custom separators. The workaround I've been using is to create blank cells (with the custom background) whenever the actual rows don't fill the entire table. However, this workaround is not feeling very practical.

Things would be much simpler if I could either modify the default separator's thickness...is there any way to do this, or something similar?


回答1:


Well I figured it out. It's actually quite simple, but there's bad news and good news. The bad news is that the separators are actually their own view classes added as subviews to the tableView, and these classes are part of Apple's undocumented API. Thus, any modification of them wouldn't sit well with Apple.

The good news is that you don't need to do anything with the undocumented classes in order to thicken the separator lines. You can simply add in your own subviews as separators. Personally I'd rather have the lines drawn in as opposed to using the subview mechanism (since all the new subviews could potentially make a large table choppy), but since we don't have access to _UITableViewSeparatorView, I'll take what I can get :)




回答2:


I have answered a relevant question here.. Go in the drawRect Method and just increase the line width according to your needs.

Do remember that this code is for grouped tables and you have to modify the code a little bit for your tableview(if you are using plain table.)

Hope this helps.

Thanks,

Madhup



来源:https://stackoverflow.com/questions/2151587/is-there-any-way-to-modify-a-uitableviews-separator-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!