Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS–;具有自定义单元格背景的普通UITableView_Ios_Cocoa Touch_Uitableview - Fatal编程技术网

iOS–;具有自定义单元格背景的普通UITableView

iOS–;具有自定义单元格背景的普通UITableView,ios,cocoa-touch,uitableview,Ios,Cocoa Touch,Uitableview,我在普通模式下使用的是UITableView,因为我希望有粘性的部分标题。我有一个自定义背景图像,它是为单元格的backgroundView设置的,但此图像会拉伸到UITableView的整个宽度 我怎样才能防止它拉伸?我尝试过设置UIViewContentModeCenter但没有效果,但我真的不知道该将其设置为哪个视图(表格视图、单元格?单元格的contentView?背景视图始终适合整个单元格。所以你有一个容器视图- UIView *cntr = [UIView alloc] initWi

我在普通模式下使用的是
UITableView
,因为我希望有粘性的部分标题。我有一个自定义背景图像,它是为单元格的
backgroundView
设置的,但此图像会拉伸到
UITableView
的整个宽度


我怎样才能防止它拉伸?我尝试过设置
UIViewContentModeCenter
但没有效果,但我真的不知道该将其设置为哪个视图(表格视图、单元格?单元格的contentView?

背景视图始终适合整个单元格。所以你有一个容器视图-

UIView *cntr = [UIView alloc] initWithFrame:<whole cell frame>]
[cntr addSubview:myCustomView];
UIView*cntr=[UIView alloc]initWithFrame:]
[cntr addSubview:myCustomView];

我实际上没有尝试在
背景视图上设置
UIViewContentModeCenter
。因此,设置使图像不拉伸

请尝试
uiviewContentModeScaleSpectFit
uiviewContentModeScaleSpectFill
并查看它们是否正确匹配。您是如何设置背景图像的?您是否将UIImageView设置为backgroundView?