How to fix the imageView size in UITableViewCell, cell. imageview size
UITableViewIt can be regarded as one of the most frequently-used components. Some simple information lists are often required during development.
Common List Layout
In fact, many pages are displayed in this way.imageView,textLabel,detailTextlabel, AndUITableViewCellIt provides a convenient automatic layout (when there are images and no images, the positions of textLabel and detailLabel are automatically adjusted left and right). However, the image size cannot be fixed (directly setimageView.frameCannot be fixedimageViewIn general, there are two ways to solve this problem:
- Fixed display image size (including PlaceHolder)
- Custom tableViewCell, add custom
imageView,textLabelAnddetailTextLabel
Both methods can solve this problem, but these two methods are actually quite troublesome. Can you fix the size of the imageView directly? There are some methods, you only need to reloadlayoutSubviewsYou can.
Derive UITableViewCell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
// Customize a Cell @ Interface MMCell: UITableViewCell
@ End
@ Implementation MMCell
// Reload layoutSubviews -(Void) layoutSubviews { UIImage * img = self. imageView. image; Self. imageView. image = [UIImage imageName: @ "res/PlaceHolder.png"]; [Super layoutSubviews]; Self. imageView. image = img; }
@ End
|
In this way, we only need to useMMCellIt can be fixedimageViewAnd the size isPlaceHolder.png(Generally, this page usesPlaceHolder.pngTo display the default image ).
The principle is inUItableVeiwOflayoutSubviewsDuring the callimageView.imageTo adjust the sizeimageView,textLabel,detailTextLabelBefore thatimageView.imageSetPlaceHolder.pngImage. You can set the original image after the layout is re-deployed.