【发布时间】:2015-11-21 06:14:39
【问题描述】:
当一个单元格被选中时,子类方法会覆盖 setSelected:
查看控制器代码
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
[collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionNone];
}
-(void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
[collectionView deselectItemAtIndexPath:indexPath animated:YES];
}
CollectionView 子类方法
-(void)setSelected:(BOOL)selected{
[super setSelected:selected];
if(self.isSelected){
self.myLabel.font = [UIFont boldSystemFontOfSize:10.0];
}else{
self.myLabel.font = [UIFont systemFontOfSize:10.0];
}
}
我也在尝试更改文本颜色。那么,是不是每次我选择新的 UIFont 对象都会被创建,如果设置文本颜色(一些自定义 UIColor)也会创建新对象。或者有没有更好的办法?
【问题讨论】:
标签: ios uicollectionviewcell didselectrowatindexpath