введите описание изображения здесь 1. вот результат моего кода.
здесь картинка макета для моего ограничения.
// * только для того, чтобы вы знали, что я новичок в разработке ios swift, так что я // много боролся в макете и ограничениях, так что если какой-либо из Вы // могли бы помочь мне, я буду рад *
import UIKit
class DayTableViewCell: UITableViewCell {
var chose:Bool=true
@IBOutlet weak var card: UIView!
@IBOutlet weak var main_stack: UIStackView!
@IBOutlet weak var content_view: UIView!
@IBOutlet weak var read_more_less_label: UILabel!
@IBOutlet weak var title_label: UILabel!
@IBOutlet weak var date_label: UILabel!
@IBOutlet weak var description_labe: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
card.layer.cornerRadius = 5.0
card.layer.shadowColor = UIColor.gray.cgColor
card.layer.shadowOffset = CGSize(width: 0.0, height: 0.0)
card.layer.shadowRadius = 12.0
card.layer.shadowOpacity = 0.7
// Configure the view for the selected state
description_labe.isHidden=true
let tap = UITapGestureRecognizer(target: self, action: #selector(DayTableViewCell.tapFunction))
read_more_less_label.isUserInteractionEnabled = true
read_more_less_label.addGestureRecognizer(tap)
read_more_less_label.text=LocalizationSystem.sharedInstance.localizedStringForKey(key: "read_more", comment: "")
}
@objc func tapFunction(){
if chose {
description_labe.isHidden=false
chose=false
read_more_less_label.text=LocalizationSystem.sharedInstance.localizedStringForKey(key: "read_less", comment: "")
// card.frame = CGRect(x: 0, y: 0, width: card.frame.width+description_labe.bounds.size.width, height:card.frame.height + description_labe.bounds.size.height)
}else{
description_labe.isHidden=true
chose=true
read_more_less_label.text=LocalizationSystem.sharedInstance.localizedStringForKey(key: "read_more", comment: "")
description_labe.sizeToFit()
//here i want to increase the height of my card by adding the height of //my description_labe(label)
self.card.frame = CGRect(x: 0, y: 0, width: card.frame.width+description_labe.frame.width, height:card.frame.height + heightForView(text: description_labe?.text ?? "", font: UIFont.systemFont(ofSize: 12), width: 300))
print("labe_height=\(heightForView(text: description_labe?.text ?? "", font: UIFont.systemFont(ofSize: 12), width: 300))")
//
// self.contentView.frame = CGRect(x: 0, y: 0, width: self.contentView.frame.width, height: self.contentView.frame.height + 20.0)
// card.frame = CGRect(x: 0 , y: self.card.frame.height * 0.7, width: self.card.frame.width, height: self.card.frame.height * 0.3)
//Set height
// let f = card.frame; //Grab current
// card.frame = CGRect(x: f.origin.x, y: f.origin.y, width: f.width, height: 400);
//
}
}
//To calculate height for label based on text size and width
func heightForView(text:String, font:UIFont, width:CGFloat) -> CGFloat {
let label:UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: width, height: CGFloat.greatestFiniteMagnitude))
label.numberOfLines = 0
label.lineBreakMode = NSLineBreakMode.byWordWrapping
label.font = font
label.text = text
label.sizeToFit()
return label.frame.height
}
}
введите описание изображения здесь