简体   繁体   English

尝试在 UI 图像中添加两个图像

[英]Trying to add two images in a UI image

Im new to xcode and was trying to add different images in a table row in a storyboard layout.我是 xcode 的新手,并试图在 storyboard 布局的表格行中添加不同的图像。

let image:UIImage = UIImage(named:
”ster.jpg")!

when i use this code, it makes every table the same image当我使用此代码时,它使每个表都具有相同的图像

 let image:UIImage = UIImage(named:
    ”ster.jpg", "blue.jpg")!

My goal is for the 2nd row of the table to have a different image, so when using this code it just creates an error saying " Extra argument in call"我的目标是让表格的第二行有不同的图像,所以当使用这段代码时,它只会产生一个错误,说“调用中的额外参数”

I would start by saying that the way you initialize the UIImage object is wrong.我首先要说你初始化 UIImage object 的方式是错误的。 It supports only one image at a time.它一次只支持一张图片。 Thus, you get the error of an extra argument in the call.因此,您会在调用中收到额外参数的错误。

To add two images in a row, you better use a horizontal stack view and modify some of its properties (fill equally, spacing, etc).要连续添加两个图像,您最好使用水平堆栈视图并修改其一些属性(均匀填充、间距等)。

The way I would do the thing: Drag and drop from library 2 UIImage objects.我会做这件事的方式:从库中拖放 2 UIImage 个对象。 Embed them in a horizontal stack view.将它们嵌入水平堆栈视图中。 In property inspector set the fill property to equal.在属性检查器中将填充属性设置为相等。 Make sure to add constraints.确保添加约束。

In case you are using UITableView and want to modify the cell, you will have to create a subclass of UITableViewCell and give it an identifier to use when the TableViewDataSourceDelegate object is fetching the cell data based on the identifier.如果您正在使用 UITableView 并想要修改单元格,则必须创建 UITableViewCell 的子类并为其提供一个标识符,以便在 TableViewDataSourceDelegate object 根据标识符获取单元格数据时使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM