简体   繁体   中英

UITableView cell icon and label are misplaced

I'm using default UITableViewCell and just set icon, label, detailLabel but for some reason with specific text length my icon jumps to the left top corner. The issue is resolved after switching tab to another one and back.

Here is how it looks:

图标和文字错位

How it should look like:

正确

It's related to text size and word-wrapping somehow because when I add or remove at least symbol - it works fine.

PS I've tried to tableView.reloadData on viewDidLoad, viewWillAppear etc and it doesn't help unfortunately. UITableViewCell is default, no custom xib / storyboard.

Any ideas what's going on here? Thanks!

Use auto-layout. Add constraints to icon and labels just.

Got it solved finally.

I was adding left green line like that:

let cellHeight = self.estimatedHeight(todo: todo)
let goalColorView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: 3, height: cellHeight))
cell.contentView.addSubview(goalColorView)
goalColorView.backgroundColor = todo.area.uiColor()

and just changed it to

cell.addSubview(goalColorView)

and now it works perfect.

Not sure why.. looks like contentView is just little bit tricky.

Thanks for all your suggestions!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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