[英]custom uitableviewcell reset subview frame doesn't work as I wanted
I custom a uitableviewcell with nib, and want to custom the highlighted style. 我用笔尖自定义了一个uitableviewcell,并且想要自定义突出显示的样式。 When the cell highlighted, I want to reduce the size of the subview of the cell and keep the position of the imageview in the cell not changing.
当单元格突出显示时,我想减小单元格子视图的大小,并保持imageview在单元格中的位置不变。 So, it looks like the frame of a imageview zoomed out, but the image itself stay there not changing its position.
因此,看起来图像视图的框架缩小了,但是图像本身停留在该位置,不会改变其位置。
However, this code snippet doesn't work as I wanted.Could anybody help me to figure out where I am wrong. 但是,此代码段无法按我的意愿工作,有人可以帮我弄清楚我哪里写错了。 Any help will be appreciated!
任何帮助将不胜感激!
tips: the imageview is a subview of self.frameView and frameView is a subview of frameBgView. 提示: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
{
....
}
}
EDIT: some screenshots to explain the question: 编辑:一些截图来解释这个问题:
oky i tried your solution but i got like this i am posting the code as well as the output how it looks, if there is any problem just comment , i am deleted the frameBgView
it is not required 好的,我尝试了您的解决方案,但是我像这样,我正在发布代码以及输出的外观,如果有任何问题,只是注释,我就删除了
frameBgView
这不是必需的
code 码
- (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;
}
}
and i am not using auto layout .. the result what i got is, before 而且我没有使用自动布局..我得到的结果是,之前
and after highlighted, 然后突出显示,
EDIT: 编辑:
this is the cell structure 这是细胞结构
as u can see in the picture, in content view
i hav added frameView
which is blue in colour, and within frameView
i hav added imageView
and also don't forget t set content mode scale to fill
and also auto resizing masks for both frameView
and imageView
for example 如u可以在图片中看到,在
content view
我甲肝添加frameView
其颜色为蓝色,并在frameView
我甲肝添加imageView
,也不要算了笔设置内容模式scale to fill
,并自动调整大小口罩都frameView
和imageView
为例
autoresizing masks for content view
自动调整
content view
遮罩
autoresizing masks for frameView
自动调整frameView的蒙
frameView
autoresizing masks for imageView
在自动口罩
imageView
END EDIT 结束编辑
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.