将UIActivityViewIndicator置于UITableViewCell中心?

时间:2016-09-03 14:26:16

标签: ios swift uitableview uiactivityindicatorview

如何以编程方式将UIActivityViewIndicator置于UITableViewCell内?

1 个答案:

答案 0 :(得分:0)

UITableViewController的自定义子类中尝试类似的内容:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cellIdentifier = "LoadingCell"
    var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as UITableViewCell!
    if cell == nil {
        cell = UITableViewCell(style: .Default, reuseIdentifier: cellIdentifier)
        let activityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: .Gray)
        activityIndicatorView.autoresizingMask = [.FlexibleLeftMargin, .FlexibleRightMargin, .FlexibleTopMargin, .FlexibleBottomMargin]
        activityIndicatorView.center = cell.center
        cell.contentView.addSubview(activityIndicatorView)
    }
    return cell
}