Is there any reason why we don't use subclasses of UIImageView?

∥☆過路亽.° 提交于 2019-12-05 22:31:27
Nir Levy

The reason it is subclassing UIView is so that you should, for example, display a UIActivityIndicator while the image is being downloaded. They do not show this in their example but I have used this code and it is really good. Also look at the comments for this post you will find more code examples, also including some caching and nice stuff.

Take a look at Wayne Cochra's comment. His YellowJacket.zip code is very nice.

A part of the Gang of Fours design pattern philosophy is to

"Favor 'object composition' over 'class inheritance'."

This reduces the tight coupling between ojects. Then changing one class will have less impact on the other classes in the system. This makes changes easier, resulting in a more stable, easy to maintain system.

In this case, as a previous poster mentioned, it allows the image to do other things as well, such as display a progress indicator.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!