[iOS development tutorial] How iOS fixed cell.imageView.image image size in UITableView

Source: Internet
Author: User

Any iOS development will basically encounter a list of impressions, or even a standard list, but because the number is not fixed, it needs to be displayed as a list, loaded from top to bottom. These are all about the use of UITableView.

In iOS development UITableView can be said to be the most widely used control, we usually use the software everywhere can see its shadow, similar to, QQ, Sina Weibo and other software basically everywhere is uitableview. Of course, its wide use is naturally inseparable from its powerful features.

We often use the default UITableView in the development process of the cell.imageView.image, if the picture size just like we want the size of the same words, but there is always an accident, often from the interface to obtain the size of the picture is not fixed

For example 1-1:

Figure 1-1

The size of the picture is larger than the cell height, so it is "burst", it appears very unattractive, harmonious, if the cell height is not fixed, the picture size is different, the effect is more ugly, then how do we do?

You must have a variety of solutions:

1, custom cell (if the simple cell, this is a bit of trouble, but also new cell file)

2, using the Uigraphicsbeginimagecontextwithoptions function to deal with (so far I think the simplest method)

UIImage * icon = [UIImage imagenamed:@ "Goods_1"];

Cgsize itemsize = Cgsizemake (36, 36);//fixed image size is 36*36

Uigraphicsbeginimagecontextwithoptions (ItemSize, NO, 0.0);//*1

CGRect imagerect = CGRectMake (0, 0, itemsize.width, itemsize.height);

[Icon Drawinrect:imagerect];

Cell.imageView.image = Uigraphicsgetimagefromcurrentimagecontext ();//*2

Uigraphicsendimagecontext ();//*3

Copy Code

After the completion of the diagram such as 1-2 (is not the moment beautiful many?) And will not be severely deformed oh O (∩_∩) o haha ~):

Figure 1-2

Explain here.

*

Uigraphicsbeginimagecontextwithoptions (cgsize size, BOOL opaque, cgfloat scale) This function is used to get the graphics context (the context) that handles the picture, You can draw on it and create pictures.

A size is the size of the context in which it is created, and also what is returned after the context handles the drawing

Opaque transparent switch, if the graphic is not transparent at all, set to Yes to optimize the storage of the bitmap.

Scale scaling factor

* *

Call the Uigraphicsgetimagefromcurrentimagecontext () function to get a UIImage object from the current context, so that it changes the picture out.

*

You need to call the Uigraphicsendimagecontext () function after you have finished manipulating the picture to close the context.

Summarize

The above is the entire content of this article, I hope that the content of this article on everyone's study or work has a certain reference learning value, if there are questions you can message exchange, thank you to the programmer's home support.

http://www.kmjdad.com/

http://www.jnsjzyy.com/

http://www.czhkwl.com/

http://www.express-o2o.com/

http://www.gzjindao.com/

http://www.chumingchuanmeiyishu.com/

http://www.thcxb.com/

http://www.xingguangkeji.com/

http://www.gdrhsy.com/

http://www.clhuiji.com/

http://www.nxjianye.com/

http://www.tjmingsheng.com/

http://www.gangguan022.com/

http://www.zyjbp.com/

http://www.qianhangmy.com/

http://www.tzminbell.com/

[iOS development tutorial] How iOS fixed cell.imageView.image image size in UITableView

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.