Tableview Cell How Do We Resize Cell in Swift Along with Image and Label

tableview cell how do we resize cell in swift along with image and label

Give constrain to your lable hight greater equal and put line to 0.

var pickheight: CGFloat = 0.0

Write this line in

override func viewDidLoad() {
super.viewDidLoad()
tableTrip.rowHeight = UITableViewAutomaticDimension
}

Method for increase tableview cell .

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

pickheight = self.findHeightForText("Pass your text here like array value as String ", havingWidth: self.view.frame.size.width - 116, andFont: UIFont.systemFontOfSize(14.0)).height

return "YOUR_DEFALUT_CELL_SIZE" + pickheight
}

Method for find text hight for cell..
Its my label constrain ...

func findHeightForText(text: String, havingWidth widthValue: CGFloat, andFont font: UIFont) -> CGSize {
var size = CGSizeZero
if text.isEmpty == false {
let frame = text.boundingRectWithSize(CGSizeMake(widthValue, CGFloat.max), options: .UsesLineFragmentOrigin, attributes: [NSFontAttributeName: font], context: nil)
size = CGSizeMake(frame.size.width, ceil(frame.size.height))
}
return size
}

How to resize a cell.imageView in a TableView and apply tintColor in Swift

You can do it by another way :

1) Create custom cell with your own UIImageView size and 2 separate labels

2) Add UIImageView as Subview of Cell

var cellImg : UIImageView = UIImageView(frame: CGRectMake(5, 5, 50, 50))
cellImg.image = UIImage(named: "yourimage.png")
cell.addSubview(cellImg)

Resize UITableViewCell to fit label or image and rounded corners

Here is one possible solution - may not be the best, may not do exactly what you need, but might get you on your way...

Instead of trying to manipulate the layers / masks from within your custom UITableViewCell class, use a UIView subclass as the image holder. The code of that class can handle the rounded corners and layer/mask size updating.

See example here: https://github.com/DonMag/dhImage

resize image in table view cell

You can change the frame of the imageView like this:

CGRect frame = imageView.frame;
frame.size.height = 30.0;
/* other frame changes ... */
imageView.frame = frame;

You should also look at the UIImageView contentMode property (see this post). It gives you control over how the image is drawn, and is actually a UIView property (so UIImageView inherits it). It gives you the following options:

Specifies how a view adjusts its content when its size changes.

typedef enum {
UIViewContentModeScaleToFill,
UIViewContentModeScaleAspectFit,
UIViewContentModeScaleAspectFill,
UIViewContentModeRedraw,
UIViewContentModeCenter,
UIViewContentModeTop,
UIViewContentModeBottom,
UIViewContentModeLeft,
UIViewContentModeRight,
UIViewContentModeTopLeft,
UIViewContentModeTopRight,
UIViewContentModeBottomLeft,
UIViewContentModeBottomRight,
} UIViewContentMode;

Dynamic height table cell in IOS with multiple labels

Well, apparently the problem was the 'distribution' property of the StackView... Changing it to 'Equal Spacing' instead 'Fill proportionally' fixed it... Thanks!



Related Topics



Leave a reply



Submit