添加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];
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];
相关文章推荐
- 第六天,UITableView,和cell的基础介绍
- iOS(学习3) UITextField 常用属性
- sequelize常见操作使用方法(增删改查,手把手教学)
- Easyui Datagrid自己创建一个编辑器
- Arduino串口读取夏普GP2Y1051
- UICollectionView
- request重定向或者是response转发请求后面的代码依然执行
- LeetCode 52. N-Queens II
- Range Sum Query - Immutable ----- 查询区间和
- 【iOS开发】UIBezierPath
- UI之Label自适应高度和宽度
- String,StringBuilder,StringBuffer
- BuildConfig.DEBUG
- 61. Implement Stack using Queues
- NGUI Button禁用(isEnabled和SetState区别)
- leetcode 62. Unique Paths
- C#--SelectedIndexChanged事件, SelectedValueChanged事件和SelectionChangeCommitted事件的区别及联系
- 60. Implement Queue using Stacks
- UI基础整理-19
- iOS开发之自定义输入框(利用UITextField及UITextView)