قالب وردپرس درنا توس
Home / Apple / UIView Restrictions TextView contentSize Bug ahhhhhh: AppleMusic

UIView Restrictions TextView contentSize Bug ahhhhhh: AppleMusic



I have a function that returns a UIView. I will dynamically resize my UIView (fullView) based on how much text is displayed in UITextView (thirdTextView).

I've tried to set the height depending on sizeThatFits of thirdTextView, but it emits "30" each time no matter how much text is in it? What am I doing wrong?

func returnView (text1: String, text2: String) -> UIView {

la fullView = UIView ()

] fullView.backgroundColor = UIColor (red: 0.82, green: 0.83, blue: 0.85, alpha: 1

.0)

la firstButton = UIButton ()

firstButton.translatesAutoresizingMaskIntoConstraints = false

[second45500]] secondButton.

thirdTextView.text = "Lorem Ipsum is simply dummy text by the printing and keyboard industry. Lorem Ipsum has been the industry's standard dummy text ever since the 16th century, when an unknown writer took a kitchen off type and scrambled it to make a type of spe cimen book. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 16th century, when an unknown writer took a type gallery and scrambled it to create a typewriter. "

thirdTextView.backgroundColor = .clear

thirdTextView.isScrollEnabled = false

firstButton.setTitle (" Button1 "for: Normal )

firstButton.setTitleColor (.black for: normal)

firstButton.titleLabel? .Font = UIFont.systemFont (ofSize: 15, weight: UIFont.Weight .medium)

firstButton.contentHorizontalAlignment = .left

secondButton.setTitle ("Button2" for :. normal)

secondButton. setTitleColor (.black for: normal) [19659002] secondButton.titleLabel? .Font = UIFont.systemFont (ofSize: 15, weight: UIFont.Weight.medium)

secondButton.contentHorizontalAlignment = ]

viewWithStackViews.axis = .vertical

viewWithStackViews.layoutMargins = UIEdgeInsets (top: 15, left: 10, bottom: 5, right: 10) [19659002] viewWithStackViews.isLayoutMarginsRelativeArrangement = true

] fullView.addSubview (viewWithStackViews)

NSLayoutConstraint (element: descriptionBarStackView, attribute: NSLayoutConstraint.A ttribute.height, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute , multiplier: 1, constant: 30) .isActive = true

NSLayoutConstraint.activate (

viewWithStackViews.topAnchor.constraint (likeTo: fullView.topAnchor, constant: 0 ),

viewWithStackViews.leadingAnchor.constraint (likeTo: fullView.leadingAnchor, constant: 0),

viewWithStackViews.trailingAnchor.constraint (likeTo: fullView.trailingAnchor, constant : 0),

viewWithStackViews.bottomAnchor.constraint (likTil: fullView.bottomAnchor, constant: 0),

])

] test = thirdTextView.sizeThatFits (thirdTextView.frame.size) .height

print test)

fullView.frame = CGRect (x: 0, y: 0, width : textView.frame.width - 10, height: test)

fullView.layer.cornerRadius = 5

return fullView

]


Source link