ios - 如何将两个 UIImage 添加到 UITableView 背景

标签 ios iphone objective-c uitableview

我在 iPhone 屏幕的每一侧都有两张带有花朵的图像。我想将这些图像添加到 UITableView 背景。

截图

enter image description here

问题是 :如何以编程方式或使用 Storyboard 添加它?
我想在每个 iPhone 屏幕上使用这种花,可以吗?或者我应该在 Storyboard 的每个 ViewController 中添加它?

我做的代码

UIImageView *leftFlowersIView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 36, 455)];
    [leftFlowersIView setImage:[UIImage imageNamed:@"flower_left.png"]];
    [self.tableView.backgroundView addSubview:leftFlowersIView];
    UIImageView *rightFlowersIView = [[UIImageView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 36, 0, 36, 455)];
    [rightFlowersIView setImage:[UIImage imageNamed:@"flower_right.png"]];
    [self.tableView.backgroundView addSubview:rightFlowersIView];

我收到一个空白背景。
[self.view addSubview:leftFlowersIView];

它有效,但是当我向下滚动时 - 背景也在滚动。
self.tableView.backgroundView = leftFlowersIView;

图像被拉伸(stretch)以填满屏幕。

在此先感谢,阿尔乔姆。

结果是
    UIImageView *backgroundIView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    UIImageView *leftFlowersIView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 36, 455)];
    [leftFlowersIView setImage:[UIImage imageNamed:@"flower_left.png"]];
    [backgroundIView addSubview:leftFlowersIView];
    UIImageView *rightFlowersIView = [[UIImageView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 36, 0, 36, 455)];
    [rightFlowersIView setImage:[UIImage imageNamed:@"flower_right.png"]];
    [backgroundIView addSubview:rightFlowersIView];

    self.tableView.backgroundView = backgroundIView;

最佳答案

为此,您可以制作一个框架等于表格 View 框架的单个图像,然后只需添加以下代码:

tableview.backgroundColor = [UIColor colorWithPatternImage:yourimage];

关于ios - 如何将两个 UIImage 添加到 UITableView 背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21109706/

相关文章:

iphone - "Incorrect signature"来自 FBVideoUpload 请求

iPhone Xs 和 Xs Max 在 iTunes 上没有显示 UDID?

objective-c - Xcode 中的循环音频

ios - Xcode:应用程序构建,但同时构建 "runs"和 "finishes"

html - iOS 辅助功能旁白读出 Web 中不必要的内容

objective-c - 如何将 UIImageView 上的触摸限制为其 UIImage 的不透明部分?

objective-c - 自定义 Getter & Setter iOS 5

objective-c - NSTableView 的绑定(bind)值,但工具提示也被设置

iphone - iOS 上的蓝牙连接 - 建立连接时应用程序崩溃

ios - 类 'ProductDetailViewController' 没有初始化器