В моем приложении я изменяю текст нижнего колонтитула своего табличного представления динамически, когда я выбираю ячейку. К сожалению, способ, которым я это делаю, изменяет рамку UILabel
в пределах моего UIView
. Например, когда я нажимаю на ячейку, ширина моей метки становится чем-то между 950 и 1200. Когда на самом деле ширина должна быть (не более) шириной вида. Вот мой код:Динамическая настройка и изменение размера метки в нижнем колонтитуле UITableView
def tableView(tableView, viewForFooterInSection:section)
(section != (self.sections.count - 1)) ? footer_view : nil
end
def tableView(tableView, heightForFooterInSection: section)
if section != (self.sections.count - 1)
footer_label.frame.size.height + 20.0
else
1.0
end
end
def tableView(tableView, didSelectRowAtIndexPath: indexPath)
tableView.beginUpdates
footer_label.text = "Details: #{updated_details}"
footer_label.sizeToFit
tableView.endUpdates
end
def footer_view
@footer_view ||= UIView.alloc.initWithFrame(CGRectZero).tap do |fv|
fv.addSubview(footer_label)
end
end
def footer_label
@footer_label ||= UILabel.alloc.initWithFrame(CGRectZero).tap do |pl|
pl.frame = CGRect.new(
[15, 10],
[self.view.frame.size.width - 30, self.view.frame.size.height]
)
pl.font = UIFont.preferredFontForTextStyle(UIFontTextStyleCaption2)
pl.numberOfLines = 0
pl.lineBreakMode = NSLineBreakByWordWrapping
pl.text = ""
pl.sizeToFit
end
end
Я предполагаю, называя sizeToFit
является частью проблемы?
Ваш случай похож на [это один] (http://stackoverflow.com/questions/39825290/make-uicollectionview- заголовок динамическая высота/39832379 # 39832379)? –