contentMode屬性
帶有scale單詞的:圖片有可能會拉伸
UIViewContentModeScaleToFill
將圖片拉伸至填充整個imageView
圖片顯示的尺寸跟imageView的尺寸是一樣的
帶有aspect單詞的:保持圖片原來的寬高比
UIViewContentModeScaleAspectFit
保證剛好能看到圖片的全部
UIViewContentModeScaleAspectFill
拉伸至圖片的寬度或者高度跟imageView一樣
沒有scale單詞的:圖片絕對不會被拉伸萤厅,保持圖片的原尺寸
UIViewContentModeCenter
UIViewContentModeTop
UIViewContentModeBottom
UIViewContentModeLeft
UIViewContentModeRight
UIViewContentModeTopLeft
UIViewContentModeTopRight
UIViewContentModeBottomLeft
UIViewContentModeBottomRight
小語法點
不能直接修改:OC對象的結(jié)構(gòu)體屬性的成員
下面的寫法是錯誤的
imageView.frame.size= imageView.image.size;
正確寫法
//在OC中對象結(jié)構(gòu)體成員的修改,可以創(chuàng)建一個臨時的結(jié)構(gòu)體來取值CGRecttempFrame = imageView.frame;tempFrame.size= imageView.image.size;imageView.frame= tempFrame;
initWithImage:方法
利用這個方法創(chuàng)建出來的imageView的尺寸和傳入的圖片尺寸一樣
修改frame的3種方式
直接使用CGRectMake函數(shù)
imageView.frame=CGRectMake(100,100,200,200);
利用臨時結(jié)構(gòu)體變量
CGRecttempFrame = imageView.frame;tempFrame.origin.x=100;tempFrame.origin.y=100;tempFrame.size.width=200;tempFrame.size.height=200;imageView.frame= tempFrame;
使用大括號{}形式
imageView.frame= (CGRect){{100,100}, {200,200}};
抽取重復(fù)代碼
將相同代碼放到一個新的方法中
不用的東西就變成方法的參數(shù)
圖片的加載方式
有緩存
UIImage*image = [UIImageimageNamed:@"圖片名"];
使用場合:圖片比較小建椰、使用頻率較高
建議把需要緩存的圖片直接放到Images.xcassets
無緩存
NSString*file = [[NSBundlemainBundle] pathForResource:@"圖片名"ofType:@"圖片的擴展名"];UIImage*image = [UIImageimageWithContentsOfFile:@"圖片文件的全路徑"];
使用場合:圖片比較大卵凑、使用頻率較小
不需要緩存的圖片不能放在Images.xcassets
放在Images.xcassets里面的圖片,只能通過圖片名去加載圖片
延遲做一些事情
[abc performSelector:@selector(stand:) withObject:@"123"afterDelay:10];// 10s后自動調(diào)用abc的stand:方法蠢络,并且傳遞@"123"參數(shù)
音頻文件的簡單播放
// 創(chuàng)建一個音頻文件的URL(URL就是文件路徑對象)NSURL*url = [[NSBundlemainBundle] URLForResource:@"音頻文件名"withExtension:@"音頻文件的擴展名"];// 創(chuàng)建播放器self.player= [AVPlayerplayerWithURL:url];// 播放[self.playerplay];
UIImageView的常見屬性
@property(nonatomic,retain)UIImage*image;顯示的圖片@property(nonatomic,copy)NSArray*animationImages;顯示的動畫圖片@property(nonatomic)NSTimeIntervalanimationDuration;動畫圖片的持續(xù)時間@property(nonatomic)NSIntegeranimationRepeatCount;動畫的播放次數(shù)(默認是0,代表無限播放)
UIImageView的常見方法
-(void)startAnimating//開始動畫
-(void)stopAnimating;//停止動畫
-(BOOL)isAnimating;//是否正在執(zhí)行動畫
UIImage
一個UIImage對象代表一張圖片熬的,一般通過imageNamed:方法就可以通過文件名加載項目中的圖片
例子
UIImage*image = [UIImageimageNamed:@"lufy"];
UILabel
設(shè)置顯示多少行,要想顯示所有的行數(shù),設(shè)置為0
label.numberOfLines =2;
@property(nonatomic,copy)NSString*text;顯示的文字@property(nonatomic,retain)UIFont*font;字體@property(nonatomic,retain)UIColor*textColor;文字顏色@property(nonatomic)NSTextAlignmenttextAlignment;對齊模式(比如左對齊点寥、居中對齊咕村、右對齊)@property(nonatomic)NSIntegernumberOfLines;文字行數(shù)@property(nonatomic)NSLineBreakModelineBreakMode;換行模式
UIFront
UIFont代表字體场钉,常見創(chuàng)建方法有以下幾個:
1系統(tǒng)默認字體 + (UIFont *)systemFontOfSize:(CGFloat)fontSize;
2粗體 + (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize;
3斜體 + (UIFont *)italicSystemFontOfSize:(CGFloat)fontSize;
可以不用記,當需要時,要學(xué)會自學(xué),跳到頭文件中,查看就可以,不懂的可以自己動手測試出來
UIButton
UIbutton的狀態(tài)
normal(普通狀態(tài))
默認情況(Default)
對應(yīng)的枚舉常量:UIControlStateNormal
highlighted(高亮狀態(tài))
按鈕被按下去的時候(手指還未松開)
對應(yīng)的枚舉常量:UIControlStateHighlighted
disabled(失效狀態(tài),不可用狀態(tài))
如果enabled屬性為NO懈涛,就是處于disable狀態(tài)惹悄,代表按鈕不可以被點擊
對應(yīng)的枚舉常量:UIControlStateDisabled
設(shè)置按鈕在不同狀態(tài)的背景圖片
![](http://localhost:44244/raw/_/L1VzZXJzL2tlbnpoYW8vR2l0Qm9vay9MaWJyYXJ5L0ltcG9ydC91aWJhc2lj/master/button.png?token=Y3FsZWU6ZWVmMDFkMmQtZjAyZC00Y2JiLThkNjctNmZjMjYyMTI4MGUz)
![](http://localhost:44244/raw/_/L1VzZXJzL2tlbnpoYW8vR2l0Qm9vay9MaWJyYXJ5L0ltcG9ydC91aWJhc2lj/master/button1.png?token=Y3FsZWU6ZWVmMDFkMmQtZjAyZC00Y2JiLThkNjctNmZjMjYyMTI4MGUz)
按鈕的樣式
![](http://localhost:44244/raw/_/L1VzZXJzL2tlbnpoYW8vR2l0Qm9vay9MaWJyYXJ5L0ltcG9ydC91aWJhc2lj/master/picture1.png?token=Y3FsZWU6ZWVmMDFkMmQtZjAyZC00Y2JiLThkNjctNmZjMjYyMTI4MGUz)
![](http://localhost:44244/raw/_/L1VzZXJzL2tlbnpoYW8vR2l0Qm9vay9MaWJyYXJ5L0ltcG9ydC91aWJhc2lj/master/picture.png?token=Y3FsZWU6ZWVmMDFkMmQtZjAyZC00Y2JiLThkNjctNmZjMjYyMTI4MGUz)
UIButton的常見設(shè)置
- (void)setTitle:(NSString *)titleforState:(UIControlState)state;設(shè)置按鈕的文字
- (void)setTitleColor:(UIColor *)colorforState:(UIControlState)state;設(shè)置按鈕的文字顏色
- (void)setImage:(UIImage *)imageforState:(UIControlState)state;設(shè)置按鈕內(nèi)部的小圖片
- (void)setBackgroundImage:(UIImage *)imageforState:(UIControlState)state;設(shè)置按鈕的背景圖片
btn.titleLabel.font = [UIFont systemFontOfSize:13];設(shè)置按鈕的文字字體(需要拿到按鈕內(nèi)部的label來設(shè)置)
- (NSString *)titleForState:(UIControlState)state;獲得按鈕的文字
- (UIColor *)titleColorForState:(UIControlState)state;獲得按鈕的文字顏色
- (UIImage *)imageForState:(UIControlState)state;獲得按鈕內(nèi)部的小圖片
- (UIImage *)backgroundImageForState:(UIControlState)state;獲得按鈕的背景圖片
choose for the UIImageView and UILabel and UIButton
UIButton、UIImageView肩钠、UILabel的選擇
僅僅是顯示數(shù)據(jù),不需要點擊
建議選擇UIImageView暂殖、UILabel
不僅顯示數(shù)據(jù)价匠,還需要監(jiān)聽點擊
建議選擇UIButton
其實UIImageView、UILabel也可以通過手勢識別器來監(jiān)聽
長按控件后呛每,會改變顯示的內(nèi)容
不用考慮了踩窖,選擇UIButton(因為UIButton有highlighted這種狀態(tài))
同時顯示2張圖片:背景圖片、內(nèi)容圖片
不用考慮了晨横,選擇UIButton