您的位置:首页 > 产品设计 > UI/UE

添加UIview自定义的分割线、去掉默认的cell分割线、默认选中某一个(行)cell的方法

2016-01-22 22:55 549 查看
//添加分割线 在tableView的cell中

UIView
* lineView = [[
UIView
alloc]init];

lineView.backgroundColor= [

UIColor
blackColor];

[self.contentView addSubview:lineView];

// self.lineView
= lineView;

//添加到tableView中

-(void)layoutSubviews{

[super layoutSubviews];

self.lineView.frame
=
CGRectMake(0,

79,

kWIDTH,

2);

}

去掉默认的cell分割线



cell的separatorStyle属性设置为.....None(是一个枚举,点进去就可以找到);

UICollectionView中默认选中某一个(行)cell的方法:



动态改变cell的大小;在collectionView中。是layout改变cell的大小的,要用UICollectionFlowLayout(决定cell的尺寸)的代理方法:

// 实现这个方法之后, layout.itemSize
就会失效.

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath
*)indexPath{

//获取模型数据

LZJNewsChannelModel * channel =
self.channels[indexPath.item];

// cell
的宽高. cell 的宽度等于
大 label(选中状态)
的宽

CGSize itemSize = [self
getSizeWithTname:channel.tname];

return itemSize;

}

//设置大lable的大小

-(CGSize)getSizeWithTname:(NSString *)tName{

UILabel * lable = [[
UILabel alloc]init];

lable.text = tName;

lable.font = [
UIFont systemFontOfSize:18];

//自适应高度

[lable sizeToFit];

return lable.bounds.size;

}

在collectionView中:根据indexPath滚动到某一个位置的方法:

// animated: YES ,会有动画效果,滚动中间所有的数据都会加载出来.

// animated: NO ,不会有动画效果,只会加载滚动结束之后位置的数据.

[ self
scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally
animated:NO];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: