IOS--UIButton的使用方法

來源:互聯網
上載者:User

標籤:style   blog   http   io   ar   color   os   使用   sp   

IOS--UIButton的使用方法詳細 (2013-08-23 17:20:38) 轉載▼
標籤: ios uibutton button 使用詳細 it 分類: iOS--UI

 

   // UIButton的常用方法

    UIButton *oneButton = [UIButton buttonWithType:UIButtonTypeCustom]; // 初始化時設定Button樣式

    // 風格有如下

//    typedef enum {

//        UIButtonTypeCustom = 0,           // 自訂,無風格

//        UIButtonTypeRoundedRect,        // 白色圓角矩形,類似喜好設定表格單元或者地址簿卡片

//        UIButtonTypeDetailDisclosure,//藍色的披露按鈕,可放在任何文字旁

//        UIButtonTypeInfoLight,//微件(widget)使用的小圓圈資訊按鈕,可以放在任何文字旁

//        UIButtonTypeInfoDark,//白色背景下使用的深色圓圈資訊按鈕

//        UIButtonTypeContactAdd,//藍色加號(+)按鈕,可以放在任何文字旁

//    } UIButtonType;

    

    

    // 最常用

    oneButton.frame = CGRectMake(10, 10, 300, 30); // 設定oneButton的位置和大小

    oneButton.backgroundColor = [UIColor blueColor]; // 設定oneButton背景色

    oneButton.alpha = 0.8; // 設定oneButton的透明度範圍在0.0-1.0之間

    [oneButton setTitle:@"我是一個UIButton" forState:UIControlStateNormal]; // 設定在什麼狀態下顯示什麼文字

    [oneButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];// 設定什麼狀態下字型什麼顏色

    [oneButton setBackgroundImage:[UIImage imageNamed:@"image.jpg"]forState:UIControlStateNormal]; // 設定什麼狀態下顯示的背景映像

    // 上面幾個方法都提到 共同的參數 forState . 這個參數決定了標題、映像或其他屬性將在何種狀態下顯現。你可以編程令按鈕在那個狀態變化

//    enum {

//        UIControlStateNormal       = 0,//常態

//        UIControlStateHighlighted  = 1 << 0,    //  高亮

//        UIControlStateDisabled     = 1 << 1,    //禁用

//        UIControlStateSelected     = 1 << 2,    // 選中

//        UIControlStateApplication  = 0x00FF0000,// 當應用程式標誌使用時

//        UIControlStateReserved     = 0xFF000000 // 為內部架構預留的

//    };

    oneButton.tag = 10001; // 設定標籤,用於便於點擊的是哪個按鈕,常用在委託方法中

    [oneButton.titleLabel setFont:[UIFont systemFontOfSize:25.0f]]; // 設定文字的大小

    

    oneButton.adjustsImageWhenDisabled = NO; // 對按鈕進行微調。當按鈕禁用時,映像會被畫的顏色深一些 預設是YES,禁止設定為NO

    oneButton.adjustsImageWhenHighlighted = NO; // 對按鈕進行微調。當按鈕高亮是,映像會被畫得顏色深一些 預設是YES,禁止設定為NO

    

    oneButton.showsTouchWhenHighlighted = YES; // 設定點擊的時候是否有光照得效果

    

    // 給按鈕添加響應事件

    [oneButton addTarget:self action:@selector(oneButtonTouchUpInside:)forControlEvents:UIControlEventTouchUpInside];//當按鈕被按下時會執行oneButtonTouchUpinside:方法。這個方法是自訂的,需要自己寫出。參數是(UIButton *)類型

    

    // 添加到view

    [self.view addSubview:oneButton];

 

IOS--UIButton的使用方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.