IOS學習筆記(十)之UIImageView圖檔視圖的基本概念和使用方法
Author:hmjiangqq
Email:[email protected]
UIImageView:
作用:專門用于顯示圖檔
首先看下官方的解說:
An p_w_picpath view object provides a view-based container for displaying either a single p_w_picpath or for animating a series of p_w_picpaths. For animating the p_w_picpaths, the
UIImageView
class provides controls to set the duration and frequency of the animation. You can also start and stop the animation freely.
When a
UIImageView
object displays one of its p_w_picpaths, the actual behavior is based on the properties of the p_w_picpath and the view. If either of the p_w_picpath’s leftCapWidth
or topCapHeight
properties are non-zero, then the p_w_picpath is stretched according to the values in those properties. Otherwise, the p_w_picpath is scaled, sized to fit, or positioned in the p_w_picpath view according to the contentMode
property of the view. It is recommended (but not required) that you use p_w_picpaths that are all the same size. If the p_w_picpaths are different sizes, each will be adjusted to fit separately based on that mode.
All p_w_picpaths associated with a
UIImageView
object should use the same scale
. If your application uses p_w_picpaths with different scales, they may render incorrectly.
常用屬性和方法:
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLiQ3chVEa0V3bT9CX5RXa2Fmcn9CXwczLcVmds92czlGZvwVP9EUTDZ0aRJkSwk0LcxGbpZ2LcBDM08CXlpXazRnbvZ2LcRlMMVDT2EWNvwFdu9mZvwVPFh1YuVzVZBHcygVeWd0Y2h3VaJjVHpldRhlW1VTaitmTzkVdjJjYzpkMMZ3bENGMShUYvwFd4VGdvwlMvw1ayFWbyVGdhd3P2kjMyUzNzYTM2IjMwQTMwIzLcRXZu5ibkN3Yuc2bsJmLn1Wavw1LcpDc0RHaiojIsJye.jpg)
//建立圖檔視圖
//建立圖檔視圖
UIImageView *p_w_picpathview=[[UIImageView alloc]initWithFrame:CGRectMake(140, 100, 45, 45)];
//設定高亮
p_w_picpathview.highlighted=YES;
//設定圖檔
p_w_picpathview.p_w_picpath=[UIImage p_w_picpathNamed:@"notification_icon"];
//設定高亮圖檔
p_w_picpathview.highlightedImage=[UIImage p_w_picpathNamed:@"notification_icon"];
[self.window addSubview:p_w_picpathview];
- (id)initWithImage:(UIImage *)p_w_picpath; //初始化一張圖檔
- (id)initWithImage:(UIImage *)p_w_picpath highlightedImage:(UIImage *)highlightedImage NS_AVAILABLE_IOS(3_0);
//初始化 加入一張高亮圖檔與本身圖檔
//預設圖檔
@property(nonatomic,retain) UIImage *p_w_picpath; // default is nil
//高亮圖檔
@property(nonatomic,retain) UIImage *highlightedImage NS_AVAILABLE_IOS(3_0); // default is nil
@property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled; // default is NO
//設定為YES 使用者才可以進行點選
//設定為YES 圖檔高亮顯示
@property(nonatomic,getter=isHighlighted) BOOL highlighted NS_AVAILABLE_IOS(3_0); // default is NO