Ios 如何使文本换行?
我正在尝试制作一个应用程序,它将以一个可滚动的集合视图开始,其中包含3个图像和3个文本。但我的描述文本被iPhone边缘剪掉了 这是我的密码。怎么了Ios 如何使文本换行?,ios,swift,uicollectionview,Ios,Swift,Uicollectionview,我正在尝试制作一个应用程序,它将以一个可滚动的集合视图开始,其中包含3个图像和3个文本。但我的描述文本被iPhone边缘剪掉了 这是我的密码。怎么了 import UIKit class IntroAppCollectionViewCell: UICollectionViewCell { var data : MyData? { didSet{ guard let unWrappedData = data else { return }
import UIKit
class IntroAppCollectionViewCell: UICollectionViewCell {
var data : MyData? {
didSet{
guard let unWrappedData = data else { return }
imgFundo.image = UIImage(named: unWrappedData.imageURL)
//descriptionText.text = unWrappedData.descriptionText
let attributedText = NSMutableAttributedString(string: unWrappedData.title, attributes: [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 18),NSAttributedString.Key.foregroundColor : UIColor.white])
attributedText.append(NSAttributedString(string: "\n\n\n\(unWrappedData.descriptionText)", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 15), NSAttributedString.Key.foregroundColor: UIColor.gray]))
descriptionText.attributedText = attributedText
descriptionText.textAlignment = .center
}
}
let imgFundo : UIImageView = {
let img = UIImageView()
img.contentMode = .scaleAspectFit
img.translatesAutoresizingMaskIntoConstraints = false
return img
}()
let descriptionText : UITextView = {
let textView = UITextView()
textView.translatesAutoresizingMaskIntoConstraints = false
textView.textColor = UIColor.white
textView.textAlignment = .center
textView.backgroundColor = UIColor.black
textView.isEditable = false
textView.isSelectable = false
textView.isScrollEnabled = false
return textView
}()
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = UIColor.black
setupImg()
setupText()
}
func setupText(){
addSubview(descriptionText)
descriptionText.topAnchor.constraint(equalTo: topAnchor, constant: 5).isActive = true
descriptionText.leftAnchor.constraint(equalTo: leftAnchor, constant: 10).isActive = true
descriptionText.rightAnchor.constraint(equalTo: rightAnchor, constant: 10).isActive = true
descriptionText.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -50).isActive = true
}
func setupImg(){
addSubview(imgFundo)
imgFundo.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor).isActive = true
imgFundo.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor).isActive = true
imgFundo.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor).isActive = true
imgFundo.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor,constant: -150).isActive = true
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
更改
setupText()
函数
func setupText() {
addSubview(descriptionText)
descriptionText.topAnchor.constraint(equalTo: topAnchor, constant: 5).isActive = true
descriptionText.leftAnchor.constraint(equalTo: leftAnchor, constant: 10).isActive = true
rightAnchor.constraint(equalTo: descriptionText.rightAnchor, constant: 10).isActive = true
descriptionText.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -50).isActive = true
}
你能分享这个应用的截图吗?