【问题标题】:Full the image in tableViewController在 tableViewController 中填充图像
【发布时间】:2015-05-13 18:02:01
【问题描述】:

我正在尝试使用 Swift 编程开发一个在 Xcode 中使用 tableView 的应用程序。我已经在 tableView 中显示了图像,但图像不是全尺寸。图像仍然没有覆盖单元格的区域。

如何使图像全尺寸?

我正在使用 Xcode 6 并使用 Swift Programming。

下面是代码示例。

class FoodListTableViewController: UITableViewController {

    var food:AnyObject?

    override func viewDidLoad() {
        super.viewDidLoad()


        let path = NSBundle.mainBundle().pathForResource("food", ofType: "plist")
        let food2 = NSArray(contentsOfFile:path!)

        food = food2!   
    }

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return food!.count
    }


    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("cellfood", forIndexPath: indexPath) as! UITableViewCell

        var imageName = UIImage(named: food![indexPath.row].objectForKey("gambar")! as! String)
        cell.imageView!.image = imageName

        return cell
    }

这是我得到的屏幕截图...

http://104.223.3.210/namia/hm/Screen%20Shot%202015-05-14%20at%202.02.47%20AM.png

【问题讨论】:

  • 你说的是左边的空白吗?
  • @Amit89 yes..left hand side
  • 这是当前iOS版本的默认设置。

标签: ios xcode uitableview swift


【解决方案1】:

检查下面的代码可能会有所帮助。

cell.imageView.autoresizingMask = UIViewAutoresizing.FlexibleBottomMargin | UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleRightMargin | UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleWidth
cell.imageView.contentMode = UIViewContentMode.ScaleAspectFit

【讨论】:

  • 你能告诉我你在那边用什么样的细胞吗?
【解决方案2】:

在当前版本中,默认值为 15 像素。

对于您的查询,可以使用两种解决方法

  1. 如果您正在使用情节提要,请转到情节提要 -> 选择您的视图控制器 -> 在右侧打开“属性检查器” -> 选择“分隔符 InSet” -> 将其从默认值更改为自定义并给出 0 而不是 15在“左侧”字段中。

  2. 如果上述方法不起作用,请创建UITableViewCell 的自定义单元格子类,并在其中添加一个UIImageView,它将从单元格的零位置开始。

注意:如果您不使用自定义单元格,请删除单元格初始化代码并使用它 - let cell : UITableViewCell = UITableViewCell(style:UITableViewCellStyle.Subtitle, reuseIdentifier:"cellfood")

【讨论】:

    猜你喜欢
    • 2014-10-14
    • 2020-12-07
    • 2011-09-29
    • 1970-01-01
    • 2019-08-09
    • 1970-01-01
    • 2011-08-15
    • 2013-11-05
    • 2011-03-06
    相关资源
    最近更新 更多