I have a UITableView
in my app and I want to present there a UILabel
when there is no content. So far I'm doing:
@IBOutlet var tview: UITableView!
var emptyLabel = UILabel(frame: CGRectMake(0, 10, 100, 100))
override func viewDidLoad(){
let refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action: "refresh:", forControlEvents: .ValueChanged)
refreshControl.attributedTitle = NSAttributedString(string: "last updated on \(NSDate())")
tview.separatorStyle = UITableViewCellSeparatorStyle.None
tview.addSubview(refreshControl)
emptyLabel.numberOfLines = 0
emptyLabel.text = "There is no content in this table for now. Please pull down the list to refresh and something should appear"
emptyLabel.font = emptyLabel.font.fontWithSize(10)
tview.backgroundView = emptyLabel
}
But when I do like that, I have the following result:
and instead of the alignment to the left I would like to center the text, so that it looks something like:
There is no content in this table for now. Please pull down the
list to refresh and something should appear
Also, currently it's centered vertically - is there a way of putting this message let's say in 1/3 of the screen from the top?
====== EDIT
@Md.Muzahidul Islam this is how I present the label when the table is empty:
override func tableView(tview: UITableView, numberOfRowsInSection section: Int) -> Int {
if self.items.count == 0{
self.emptyLabel.hidden = false
return 0
} else {
self.emptyLabel.hidden = true
return self.items.count;
}
}