How to fix the imageView size in UITableViewCell, cell. imageview size

Source: Internet
Author: User

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 customimageView,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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.