2017-03-14 4 views
2

나는 내가 'lb에 의존의 높이'background_img_viewsizeThatFits을 사용하는 방법, 그것은 30 또는 300 픽셀 수 있으며, 높이를 고정하지 않는 텍스트보기이스위프트에서 sizeThatFits를 사용하는 방법?

let lb = UITextView() 
let view = UIView() 
background_img_view.addSubview(about_txt) 

lb 같은 전망을 가지고있다 에스?

답변

3

이 시도 :

// Get the width you want to fit 
let fixedWidth = textView.frame.size.width 

// Calculate the biggest size that fixes in the given CGSize 
let newSize = textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.greatestFiniteMagnitude)) 

// Set the textView's size to be whatever is bigger: The fitted width or the fixedWidth 
textView.frame.size = CGSize(width: max(newSize.width, fixedWidth), height: newSize.height) 

// Make the "background_img_view" height match the textView's height 
background_img_view.frame.size.height = textView.frame.size.height 
+0

두 번째 줄 오른쪽 중복? – monadis

+0

각 코드 행에 설명이 추가되어 그 기능이 무엇인지 말할 수 있습니까? – traisjames

관련 문제