一、關(guān)于分割線的位置愚臀。
分割線的位置就是指分割線相對于tableViewCell.如果我們要根據(jù)要求調(diào)節(jié)其位置忆蚀,那么在iOS7.0版本以后,提供了一個方法如下:
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 45, 0, 0)];
}
[self.tableView setSeparatorColor:[UIColor clearColor]];
typedef NS_ENUM(NSInteger, UITableViewCellSeparatorStyle) {
UITableViewCellSeparatorStyleNone,
UITableViewCellSeparatorStyleSingleLine,
UITableViewCellSeparatorStyleSingleLineEtched // This separator style is only supported for grouped style table views currently
};
三姑裂、tableViewCell 分割線自定義:首先要把cell自帶的分割線給去掉馋袜,使用如下兩種都行,一是把顏色設(shè)置為clearColor舶斧,二是風(fēng)格設(shè)置為UITableViewCellSeparatorStyleNone欣鳖。
自定義cell分割線大致用到的兩種方法
a、把自定義的分割線當(dāng)成一個View放到cell的contentView上茴厉,一定要注意重用問題泽台,所以這個view 要在cell初始化的時候添加上让网。示例代碼如下:
復(fù)制代碼
-
(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、比較復(fù)雜师痕,用到了底層的框架溃睹,
復(fù)制代碼
- (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));
}