天天看點

學習筆記(傳智播客視訊中的)

一、UIButton和UIImageView的差別

1.顯示圖檔

(1)UIImageView隻能顯示一種圖檔(圖檔預設會填充整個UIImageView)  image\setImage

(2)UIButton能顯示2中圖檔

*背景(背景會填充整個UIButton) setBackgroundImage: forState:

*前置(覆寫在背景上面的圖檔,按照之前的尺寸顯示) setImage: forState:

*還能顯示文字

2.點選事件

(1)UIImageView預設是不能響應點選事件

(2)UIButton能響應點選事件:addTarget:action:forControlEvents:

3.使用場合

(1)UIImageView : 隻顯示圖檔,不監聽點選,點選了圖檔後不做任何反映

(2)UIButton: 既顯示圖檔,又監聽點選,點選了圖檔後做一些其他事情

4.繼承結構

(1)UIButton 之是以能添加監聽器來監聽事件,是因為它繼承自UIControl

(2)UIImageView之是以不能添加監聽器來監聽事件,點選了圖檔後做一些其他事情

二、UIImageView的幀動畫

<span style="font-size:18px;">@property(nonantomic,copy) NSArray *animationImages;//設定需要播放的圖檔(到時會按數組順序播放)

@property (nonatomic) NSTimeInterval animationDuration;//動畫的持續時間

@property (nonatomic) NSInteger animationRepeatCount;//動畫的執行次數(預設情況下是無限重複執行)



-(void)startAnimating;//開始動畫

-(void)stopAnimating;//停止動畫

-(BOOL)isAnimatng;//是否正在執行動畫
</span>
           

三、格式符補充

%03d:每個整數占據3個位置,多出的位置用0填充

比如:

*  [NSString stringWithFormat:@"%03d",0]; 傳回的是@"000"

*  [NSString stringWithFormat:@"%03d",8]; 傳回的是@"008"

*  [NSString stringWithFormat:@"%03d",15]; 傳回的是@"015"

*  [NSString stringWithFormat:@"%03d",321]; 傳回的是@"321"
           

四、加載圖檔的兩種方式

1.有緩存

UIImage *image = [UIImage imageNamed:@"a.png"];

2.無緩存

//全路徑

NSString *path =[ [NSBundle mainBundle] pathForResource:@"a.png" ofType:nil];

//path是a.png的全路徑

UIImage *image = [[UIImage alloc] initWithContentsOfFile:path];
           

五、UIToolbar的簡單使用

1.UIToolbar内部隻能放UIBarButtonItem