国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS中tableView cell分割線的一些設置技巧

2020-07-26 02:49:30
字體:
來源:轉載
供稿:網友

前言

對于iOS的tableView的cell的分割線,一般我們很少使用不是系統默認的,但是有些項目要求還是要求我們去改變分割線的顏色或者外形以配合整個項目的色調。這個蘋果公司早都為我們想到了。

一、關于分割線的位置。

分割線的位置就是指分割線相對于tableViewCell.如果我們要根據要求調節其位置,那么在iOS7.0版本以后,提供了一個方法如下:

if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {    [self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 45, 0, 0)];   }

UIEdgeInsets 的四個參數分別是相對于cell的上、左、下、右的距離,都是CGFloat型。

二、分割線的顏色及風格:

a、cell的分割線的顏色不是cell的屬性,它屬于tableView的separatorColor屬性。這樣我們只需要設置屬性值就可以得到所有我們想要的顏色的分割線、

[self.tableView setSeparatorColor:[UIColor clearColor]];

b、cell的風格:它是tableView 的separatorStyle屬性,系統給我們提供了三種風格在枚舉UITableViewCellSeparatorStyle中定義,分別是

typedef NS_ENUM(NSInteger, UITableViewCellSeparatorStyle) { UITableViewCellSeparatorStyleNone, UITableViewCellSeparatorStyleSingleLine, UITableViewCellSeparatorStyleSingleLineEtched // This separator style is only supported for grouped style table views currently};

默認的是UITableViewCellSeparatorStyleSingleLine.

三、tableViewCell 分割線自定義

首先要把cell自帶的分割線給去掉,使用如下兩種都行,一是把顏色設置為clearColor,二是風格設置為UITableViewCellSeparatorStyleNone。

自定義cell分割線大致用到的兩種方法

a、把自定義的分割線當成一個View放到cell的contentView上,一定要注意重用問題,所以這個view 要在cell初始化的時候添加上。示例代碼如下:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = nil; cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (cell == nil) {  cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];  cell.accessoryView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"huicellacce"]];  cell.backgroundColor = [UIColor clearColor];//  cell.selected = YES;  UIImageView *imageViewSepE = [[UIImageView alloc]initWithFrame:CGRectMake(47, 49, 200, 1)];  imageViewSepE.image = [UIImage imageNamed:@"godline"];  [cell.contentView addSubview:imageViewSepE]; }}

b、比較復雜,用到了底層的框架,

- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor); CGContextFillRect(context, rect); CGContextSetStrokeColorWithColor(context, [UIColorcolorWithHexString:@"ffffff"].CGColor); CGContextStrokeRect(context, CGRectMake(5, -1, rect.size.width - 10, 1)); //下分割線 CGContextSetStrokeColorWithColor(context, [UIColor colorWithHexString:@"e2e2e2"].CGColor); CGContextStrokeRect(context, CGRectMake(5, rect.size.height, rect.size.width - 10, 1)); }

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對武林網的支持。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 广昌县| 建湖县| 崇礼县| 都兰县| 黎川县| 时尚| 长岭县| 永定县| 乌苏市| 苏州市| 林周县| 司法| 普安县| 扶沟县| 莱芜市| 岑巩县| 刚察县| 尖扎县| 县级市| 同江市| 通山县| 庄河市| 普洱| 金乡县| 商城县| 和顺县| 吉木萨尔县| 锡林郭勒盟| 梁山县| 石城县| 改则县| 眉山市| 湘阴县| 海口市| 来凤县| 福贡县| 松原市| 北票市| 灵宝市| 基隆市| 萨嘎县|