国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

[ocUI日記](méi)UIImage和UIImageview

2019-11-14 18:51:07
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

UIImage

 

 1     //用類(lèi)方法創(chuàng)建uiimage(png格式可以省略后綴) 2     UIImage *image1 = [UIImage imageNamed:@"001"]; 3     //用路徑來(lái)獲得圖片 4     NSString *path = @"";//這是路徑地址 5     UIImage *image2 = [UIImage imageWithContentsOfFile:path]; 6     //根據(jù)網(wǎng)址來(lái)獲得圖片 7     NSString *url = @"";//這是網(wǎng)址 8     UIImage *image3 = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]]; 9     //uiimage繼承自u(píng)iview所以u(píng)iview的方法他都能用  所以這里就不在一一列舉10     float a = image1.size.width;//獲得圖片的寬度11     float b = image1.size.height;//獲得圖片的高度12     13     14     //nsdata和uiimage之間的轉(zhuǎn)換15     //nsdata 轉(zhuǎn)換成 uiimage16     NSData *imagedata = [NSData dataWithContentsOfFile:path];17     UIImage *image = [UIImage imageWithData:imagedata];18     //uiimage 轉(zhuǎn)化成nsdata19     NSData *imagedata1 = [NSData dataWithContentsOfFile:path];

但是寫(xiě)到這里,我們發(fā)現(xiàn)我們并不能講圖片顯示到屏幕上,并不是因?yàn)槲覀儧](méi)有寫(xiě)add方法,而是image并不能直接添加到self.view上,于是就有了下面要講的內(nèi)容

UIImageView

 1     //在創(chuàng)建uiimageview的同時(shí)添加一個(gè)參數(shù)進(jìn)去 2     UIImageView *view1 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"001"]]; 3     //設(shè)置uiimageview的位置和大小 4     view1.frame = CGRectMake(20, 20, 100, 100); 5     //設(shè)置imageview的大小和image的大小相適應(yīng) 6     [view1 sizeToFit]; 7     //添加到視圖上 8     [self.view addSubview:view1]; 9     //imageview的contentMode屬性:這個(gè)屬性是用來(lái)設(shè)置圖片的顯示方式,如居中、居右,是否縮放等10     11     /*12      UIViewContentModeScaleToFill 13      UIViewContentModeScaleaspectFit 14      UIViewContentModeScaleAspectFill 15      UIViewContentModeRedraw 16      UIViewContentModeCenter 17      UIViewContentModeTop 18      UIViewContentModeBottom 19      UIViewContentModeLeft 20      UIViewContentModeRight 21      UIViewContentModeTopLeft 22      UIViewContentModeToPRight 23      UIViewContentModeBottomLeft 24      UIViewContentModeBottomRight25      */26     //凡是沒(méi)有帶Scale的,當(dāng)圖片尺寸超過(guò) ImageView尺寸時(shí),只有部分顯示在ImageView中。UIViewContentModeScaleToFill屬性會(huì)導(dǎo)致圖片變形。 UIViewContentModeScaleAspectFit會(huì)保證圖片比例不變,而且全部顯示在ImageView中,這意味著ImageView 會(huì)有部分空白。UIViewContentModeScaleAspectFill也會(huì)證圖片比例不變,但是是填充整個(gè)ImageView的,可能只有部 分圖片顯示出來(lái)27     view1.contentMode = UIViewContentModeScaleAspectFill;

接下來(lái)給大家?guī)?lái)一個(gè)圖片輪播的demo

    //創(chuàng)建一個(gè)uiimageview    UIImageView *imagev1 = [[UIImageView alloc]initWithFrame:CGRectMake(140, 200, 100, 100)];    //創(chuàng)建image    UIImage *image1 = [UIImage imageNamed:@"101"];    UIImage *image2 = [UIImage imageNamed:@"201"];    UIImage *image3 = [UIImage imageNamed:@"301"];    UIImage *image4 = [UIImage imageNamed:@"401"];    UIImage *image5 = [UIImage imageNamed:@"501"];    UIImage *image6 = [UIImage imageNamed:@"601"];    UIImage *image7 = [UIImage imageNamed:@"701"];    //將圖片放入數(shù)組    NSArray *imagearr = @[image1,image2,image3,image4,image5,image6,image7];    //設(shè)置輪播數(shù)組    imagev1.animationImages = imagearr;    //設(shè)置播放完全部的時(shí)間    imagev1.animationDuration = 7;    //設(shè)置播放次數(shù)  0為無(wú)限循環(huán)    imagev1.animationRepeatCount = 0;    //開(kāi)始輪播    [imagev1 startAnimating];    [self.view addSubview:imagev1];

由于不會(huì)怎么插入本地視頻,所以就不放展示視頻了,大家見(jiàn)諒

 


發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 胶南市| 锡林浩特市| 云阳县| 维西| 鹰潭市| 嘉善县| 晋中市| 山阳县| 门源| 清苑县| 晋州市| 卢龙县| 两当县| 东山县| 龙泉市| 常宁市| 梁山县| 繁峙县| 定安县| 庆安县| 水城县| 繁昌县| 靖安县| 韶山市| 姚安县| 安多县| 榆树市| 牟定县| 涟水县| 龙口市| 贵港市| 鲁山县| 广德县| 上饶县| 农安县| 临颍县| 澄江县| 黔南| 静乐县| 通城县| 高陵县|