美文网首页iOS开发经验总结
ios开发:cell改变选中颜色背景图片分割线的颜色

ios开发:cell改变选中颜色背景图片分割线的颜色

作者: SadMine | 来源:发表于2017-07-30 16:23 被阅读26次

1.cell改变选中颜色背景图片分割线的颜色

1.系统默认的颜色设置
//无色 
cell.selectionStyle = UITableViewCellSelectionStyleNone;//蓝色  
cell.selectionStyle = UITableViewCellSelectionStyleBlue; //灰色  
cell.selectionStyle = UITableViewCellSelectionStyleGray;  
2.自定义颜色和背景设置
3.改变UITableViewCell选中时背景色:
UIColor *color = [[UIColoralloc]initWithRed:0.0green:0.0blue:0.0alpha:1];//通过RGB来定义自己的颜色 
cell.selectedBackgroundView = [[[UIView alloc] initWithFrame:cell.frame] autorelease];  
cell.selectedBackgroundView.backgroundColor = [UIColor xxxxxx];  
3.自定义UITableViewCell选中时背景
cell.selectedBackgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellart.png"]] autorelease];  
还有字体颜色  
cell.textLabel.highlightedTextColor = [UIColor xxxcolor]; [cell.textLabel setTextColor:color] 
4.设置tableViewCell间的分割线的颜色
[theTableView setSeparatorColor:[UIColor xxxx ]]; 

2.collection的cell重排编组

//长按手势
_longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(lonePressMoving:)];
[self.xtCollectionView addGestureRecognizer:_longPress];
- (void)lonePressMoving:(UILongPressGestureRecognizer *)longPress
{

    switch (_longPress.state) {
        case UIGestureRecognizerStateBegan: {
            {
                NSIndexPath *selectIndexPath = [self.xtCollectionView indexPathForItemAtPoint:[_longPress locationInView:self.xtCollectionView]];
                // 找到当前的cell
                XTCollectCell *cell = (XTCollectCell *)[self.xtCollectionView cellForItemAtIndexPath:selectIndexPath];
                // 定义cell的时候btn是隐藏的, 在这里设置为NO
                [cell.btnDelete setHidden:NO];
                [_xtCollectionView beginInteractiveMovementForItemAtIndexPath:selectIndexPath];
            }
            break;
        }
        case UIGestureRecognizerStateChanged: {
                [self.xtCollectionView updateInteractiveMovementTargetPosition:[longPress locationInView:_longPress.view]];
            break;
        }
        case UIGestureRecognizerStateEnded: {
                [self.xtCollectionView endInteractiveMovement];
            break;
        }
        default: [self.xtCollectionView cancelInteractiveMovement];
            break;
    }
}
- (void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath:(nonnull NSIndexPath *)sourceIndexPath toIndexPath:(nonnull NSIndexPath *)destinationIndexPath
{
    NSIndexPath *selectIndexPath = [self.xtCollectionView indexPathForItemAtPoint:[_longPress locationInView:self.xtCollectionView]];
    // 找到当前的cell
    XTCollectCell *cell = (XTCollectCell *)[self.xtCollectionView cellForItemAtIndexPath:selectIndexPath];
    [cell.btnDelete setHidden:YES];
    [self.array exchangeObjectAtIndex:sourceIndexPath.item withObjectAtIndex:destinationIndexPath.item];
    [self.xtCollectionView reloadData];
}

相关文章

网友评论

    本文标题:ios开发:cell改变选中颜色背景图片分割线的颜色

    本文链接:https://www.haomeiwen.com/subject/laqklxtx.html