我用笔尖自定义了一个uitableviewcell,并且想要自定义突出显示的样式。当单元格突出显示时,我想减小单元格子视图的大小,并保持imageview在单元格中的位置不变。因此,看起来图像视图的框架缩小了,但是图像本身停留在该位置,不会改变其位置。
但是,此代码段无法按我的意愿运行,有人可以帮我弄清楚我哪里写错了。任何帮助将不胜感激!
提示:imageview是self.frameView的子视图,frameView是frameBgView的子视图。
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
if (highlighted)
{
self.frameView.backgroundColor = UIColorFromRGBA(0, 0, 0, 0.1);
CGRect rect = self.frameBgView.frame;
rect.origin.x += 10;
rect.size.width -= 20;
self.frameBgView.frame = rect;
rect = self.frameView.frame;
rect.origin.x -= 10;
self.frameView.frame = rect;
}
else
{
....
}
}
编辑:一些截图来解释这个问题:
最佳答案
好的,我尝试了您的解决方案,但是我像这样,我正在发布代码以及输出的外观,如果有任何问题,只需注释,我就删除了frameBgView
码
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
if (highlighted)
{
self.frameView.backgroundColor = [UIColor grayColor];
CGRect rect = self.contentView.bounds;
rect.origin.x += 15;
rect.size.width -= 30;
//rect = self.frameView.frame;
// rect.origin.x -= 10;
self.frameView.frame = rect;
}
else
{
self.frameView.backgroundColor = [UIColor whiteColor];
CGRect rect = self.contentView.bounds;
rect.origin.x += 10;
rect.size.width -= 20;
self.frameView.frame = rect;
}
}
而且我没有使用自动布局..我得到的结果是,之前
然后突出显示,
编辑:
这是细胞结构
如您在图片中所见,我在
content view
中添加了蓝色的frameView
,并且在frameView
中添加了imageView
,并且不要忘记设置内容模式scale to fill
自动调整frameView
和imageView
的掩码大小自动调整
content view
的蒙版自动调整
frameView
的蒙版自动调整
imageView
的蒙版结束编辑
关于ios - 自定义uitableviewcell重置 subview 框架不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25263427/