Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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
Iphone 如何将tableViewCell背景设置为类似导航栏的黑色渐变_Iphone_Objective C_Uitableview - Fatal编程技术网

Iphone 如何将tableViewCell背景设置为类似导航栏的黑色渐变

Iphone 如何将tableViewCell背景设置为类似导航栏的黑色渐变,iphone,objective-c,uitableview,Iphone,Objective C,Uitableview,我已经设置了自己的自定义tableViewCell,希望背景相同 黑色渐变作为我的导航栏,样式为UIBarStyleBlack不透明 最好的方法是什么?使用组合键CMD-SHIFT-4捕获1像素宽的导航栏渐变图像。图像将保存在桌面上(您可以使用预览进行裁剪等)。将图像添加到项目中。在-tableView:cellforrowatinexpath:中,使用: cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imag

我已经设置了自己的自定义tableViewCell,希望背景相同 黑色渐变作为我的导航栏,样式为UIBarStyleBlack不透明


最好的方法是什么?

使用组合键CMD-SHIFT-4捕获1像素宽的导航栏渐变图像。图像将保存在桌面上(您可以使用预览进行裁剪等)。将图像添加到项目中。在
-tableView:cellforrowatinexpath:
中,使用:

cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"blackGradient.png"]];

UIKit会自动水平拉伸渐变以适应单元格的宽度。

你说得对,效果很好!谢谢这对性能有何影响?有没有更好的方法可以做到这一点?从性能上看,它肯定会增加内存使用和GPU处理,但这还不足以让您注意到。有
CAGradientLayer
,但是您不会得到与导航栏上使用的完全相同的渐变,而且性能也差不多。很多应用程序,比如Tumblr,都使用图像。