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

首頁 > 學院 > 開發(fā)設計 > 正文

iOS階段學習第27天筆記(UIButton-UIImageView的介紹)

2019-11-14 18:37:31
字體:
供稿:網(wǎng)友

iOS學習(UI)知識點整理

一、關于UIButton的介紹

1)概念:UIButton 是一種常用的控件,通過點擊觸發(fā)相應的功能

2)UIButton 的幾種常用的狀態(tài)
        1、UIControlStateNormal  正常狀態(tài)
        2、UIControlStateHighlighted 高亮狀態(tài)
        3、UIControlStateSelected 選中狀態(tài)  -> 當button的selected設置成yes之后才能觸發(fā)

3)UIButton常用的幾種事件
      1、UIControlEventTouchUpInside  按鈕按下并抬起事件
      2、UIControlEventTouchDown   按鈕按下事件
      3、UIControlEventTouchDownRepeat 按鈕多次點擊觸發(fā)事件

4)UIButton 初始化實例代碼

 1 UIButton *button = [[UIButton alloc] init]; 2 button.frame = CGRectMake(20, 50, 50 , 50); 3 button.backgroundColor = [UIColor clearColor]; 4 [button setTitle:@"按鈕1 正常狀態(tài)" forState:UIControlStateNormal]; 5 [button setTitle:@"按鈕1 高亮狀態(tài)" forState:UIControlStateHighlighted]; 6 [button setTitle:@"按鈕1 選中狀態(tài)" forState:UIControlStateSelected]; 7  8 //按鈕點擊時觸發(fā)事件 9 [button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];10 //按鈕按下后觸發(fā)事件11 [button addTarget:self action:@selector(buttonTappedDown:) forControlEvents:UIControlEventTouchDown];12 //按鈕雙擊觸發(fā)事件13 [button addTarget:self action:@selector(buttonTappedDown:) forControlEvents:UIControlEventTouchDownRepeat];14 //設置按鈕高亮狀態(tài)下的字體顏色15 [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];16 //button字體變?yōu)?5號加粗的字體17 button.titleLabel.font = [UIFont boldSystemFontOfSize:35];18 //設置圓角    19 button.layer.cornerRadius = 5.f;20 //設置邊框?qū)挾?/span>21 button.layer.borderWidth = 2.1;22 //設置邊框顏色23 button.layer.borderColor = [UIColor lightGrayColor].CGColor;24  //設置按鈕背景圖   25 UIImage *imageNormal = [UIImage imageNamed:@"camera"];26 //設置imageNormal為按鈕的正常情況的圖片27 [button setImage:imageNormal forState:UIControlStateNormal];28     29 UIImage *imageHightLight = [UIImage imageNamed:@"camera2"];30 //設置imageHightLight為按鈕的高亮情況的圖片31 [button setImage:imageHightLight forState:UIControlStateHighlighted];32 //當button設置了圖片的時候 并且沒有設置高亮狀態(tài)下得圖片,取消高亮狀態(tài), 默認是Yes33 button.adjustsImageWhenHighlighted = YES;    34 [self.window addSubview:button];

 
5)防止按鈕多次點擊重復提交數(shù)據(jù)的實例代碼

 1 [button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];  3 - (void)buttonTapped:(UIButton *)button 4 { 5     //設置按鈕不可點擊 6     button.userInteractionEnabled = NO;   8     //延遲執(zhí)行方法 防止按鈕被快速點擊或者不希望點擊造成錯誤 9     [self performSelector:@selector(delayMethod:) withObject:button afterDelay:1]; 11 }12 13 //延遲方法->設置按鈕為可點擊狀態(tài)14 - (void)delayMethod:(UIButton *)button15 {16     button.userInteractionEnabled = YES;    17 }

 

二、關于UIImageView的介紹

1)概念:UIImageView 是iOS中專門用于展示圖片的控件

2)UIImageView 初始化 實例代碼

 1     UIImageView *imageView = [[UIImageView alloc] init]; 2     imageView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.width); 3     imageView.backgroundColor = [UIColor whiteColor]; 4     imageView.center = self.view.center; 5  6     //tag設置控件的唯一標識,值不能重復 7     imageView.tag = 100; 8  9     //UIImageView的 clipsToBounds屬性,設置為yes的時候超出部分,不予以顯示10     imageView.clipsToBounds = YES;11 12     //讀取一張圖片13     UIImage *image = [UIImage imageNamed:@"icon"];14     imageView.image = image;15 16     //設置圖片展示模式17     imageView.contentMode = UIViewContentModeScaleaspectFill;18 19     //打開imageview的用戶交互 注:要實現(xiàn)圖片點擊事件此屬性必須設置為YES20     imageView.userInteractionEnabled = YES;21     [self.view addSubview:imageView];22 23     //為UIImageView添加點擊事件  24     UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self 
action:@selector(imageViewTapped:)];
25 [imageView addGestureRecognizer:tap];

 
3)UI_ImageView中常用的幾種填充模式
   1、UIViewContentModeScaleToFill  拉伸image使其充滿UIImageView
   2、UIViewContentModeScaleAspectFill 拉伸image使其不變形,并且充滿UIImageView
   3、UIViewContentModeScaleAspectFit 拉伸imgage使其不變形,并且完全顯示在UIImageView中

4)UITapGestureRecognizer  除了可以給UI_ImageView添加點擊方法外還可以給其他控件添加點擊方法
     如:UI_Lable、UI_View...等

5)iOS中獲取圖片的三種方法
 方法一: 

1 //把圖片對象加載到內(nèi)存中2 UIImage *image1 = [UIImage imageNamed:@"camera"];3 CGSize size = image1.size;4 NSLog(@"size.w %f   size.h %f",size.width ,size.height);5 //如果圖片的格式是png,則后綴名可以省略,其他格式不能省略6 UIImage *image2 = [UIImage imageNamed:@"icon.jpeg"];

方法二: 

//使用場景:讀取大圖片,比較占內(nèi)存的,需要及時釋放的圖片要用這種方法 //讀取icon.jpegNSString *imagePath3 = [[NSBundle mainBundle] pathForResource:@"icon" ofType:@"jpeg"];UIImage *image3 = [[UIImage alloc] initWithContentsOfFile:imagePath3];NSString *imagePath3_1 = [[NSBundle mainBundle] pathForResource:@"icon.jpeg" ofType:nil];UIImage *image3_1 = [[UIImage alloc] initWithContentsOfFile:imagePath3_1];

方法三:

1 NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"icon" ofType:@"jpeg"];2 3  UIImage *image4 = [UIImage imageWithContentsOfFile:imagePath];

 


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 山阳县| 庄河市| 崇礼县| 天柱县| 古丈县| 嵩明县| 新干县| 玉龙| 湖北省| 梁山县| 南川市| 江北区| 万盛区| 南城县| 廉江市| 杭州市| 桦川县| 华亭县| 鹤峰县| 长岭县| 太康县| 武威市| 灌南县| 于田县| 武山县| 阿勒泰市| 剑川县| 板桥市| 尉犁县| 石景山区| 思南县| 荆门市| 武平县| 乌鲁木齐市| 临江市| 金沙县| 简阳市| 太白县| 靖远县| 双鸭山市| 栾川县|