【问题标题】:UICollectionViewCell make font bold on selection and regular when deselected - Memory footprintUICollectionViewCell 在选择时使字体变粗,在取消选择时使字体变粗 - 内存占用
【发布时间】: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


    【解决方案1】:

    视图控制器代码是多余的。系统会自动完成所有这些操作。

    关于创建 UIFont 对象,开销很小,您无需担心。

    【讨论】:

      猜你喜欢
      • 2010-10-12
      • 2015-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多