#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor grayColor];
//獲取圖片:圖片名要加拓展名,png格式除外
UIImage *image = [UIImage imageNamed:@"stop_red.JPG"];
//圖片的拉伸
//CapInset 端蓋
//leftCap 水平拉伸的位置
//topCap 垂直拉伸的位置
// UIImageResizingModeTile, 平鋪
// UIImageResizingModeStretch 拉伸
//1.創(chuàng)建一個imageView --> frame和image必備的
UIImageView *imageView = [[UIImageView alloc]init];
//默認圖片
imageView.image = image;
//圖片視圖的frame
// imageView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
imageView.frame = CGRectMake(0, 50, 300, 300);
//標簽
imageView.tag = 100;
//高亮圖片:圖片高亮狀態(tài)下顯示
imageView.highlightedImage = [UIImage imageNamed:@"stop_yellow.JPG"];
//是否開啟高亮狀態(tài) 默認NO
//內容方式
/*
UIViewContentModeScaleToFill, 拉伸
UIViewContentModeScaleAspectFit, 水平自適應
UIViewContentModeScaleAspectFill, 垂直自適應
UIViewContentModeRedraw, // redraw on bounds change (calls -setNeedsDisplay)
UIViewContentModeCenter, // contents remain same size. positioned adjusted.
UIViewContentModeTop,
UIViewContentModeBottom,
UIViewContentModeLeft,
UIViewContentModeRight,
UIViewContentModeTopLeft,
UIViewContentModeTopRight,
UIViewContentModeBottomLeft,
UIViewContentModeBottomRight,
*/
imageView.contentMode = UIViewContentModeScaleAspectFill;
/*
CALayer 顯示層屬性
*/
//圓角
// imageView.layer.cornerRadius = 150;
//邊線:寬度
imageView.layer.borderWidth = 5;
//邊線:顏色
imageView.layer.borderColor = [[UIColor greenColor]CGColor];
//邊緣裁剪:超出范圍的視圖不顯示
imageView.clipsToBounds = YES;
//3.添加到視圖顯示
[self.view addSubview:imageView];
}
- (IBAction)animation:(id)sender {
//1.圖片數(shù)組
NSMutableArray *array = [[NSMutableArray alloc]init];
//遍歷圖片數(shù)組
for (int i = 0; i < 13; i++) {
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"cat_cymbal00%02d.jpg",i]];
[array addObject:image];
}
//2.設置動畫數(shù)組
UIImageView *imageView = [[UIImageView alloc]init];
//設置圖的大小
imageView.frame = CGRectMake(0, 350, 200, 350);
//返回
[self.view addSubview:imageView];
imageView.animationImages = array;
//3.設置動畫屬性
//播放時間
imageView.animationDuration = 1;
//重復次數(shù),系統(tǒng)默認無限次
// imageView.animationRepeatCount = 1;//出現(xiàn)錯誤斷點查詢
//4.啟動動畫
[imageView startAnimating];
//5.停止動畫
// [imageView stopAnimating];//運行后不顯示動畫
}
- (IBAction)highlight:(id)sender {
UIImageView *iv = [self.view viewWithTag:100];
//切換狀態(tài) 聰明
iv.highlighted =! iv.highlighted;
// //笨點
// if (iv.highlighted == NO) {
//
// iv.highlighted = YES;
// }else{
//
// iv.highlighted = NO;
// }
}
@end
lighted //點燃
highlighted //高亮
layer //層
clips //剪輯
bounds //界限
radius //半徑
corner //角
cornerRadius //圓角
屏幕快照 2016-02-24 下午8.36.39.png