轉-UIButton定義和設定圓角

來源:互聯網
上載者:User

標籤:

//login button    //  .h 中定義    UIButton *_loginBtn;    @property (strong,nonatomic)UIButton *loginBtn;            // .m 中實現設定按鈕    @synthesize loginBtn = _loginBtn;//使用備份變數名        //設定按鈕的  形狀    self.loginBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];    /*     buttonWithType:  定義button按鈕的外形     六種定義button類型: 下面有圖解     UIButtonTypeCustom = 0,    無類型     UIButtonTypeRoundedRect,    四個角是圓弧   型的     UIButtonTypeDetailDisclosure,     UIButtonTypeInfoLight,     UIButtonTypeInfoDark,     UIButtonTypeContactAdd,     */        //定義button按鈕在frame上的座標(位置),和這個按鈕的寬/高    self.loginBtn.frame = CGRectMake(40, 200, 80, 30);            [self.loginBtn setTitle:@"Login" forState:UIControlStateNormal];    /*     常用的屬性:      setTitle:  設定button按鈕的名稱      setImage: [UIImage imageNamed:@"圖名"]  添加圖片      setTitleColor:[UIColor redColor]  設定字型顏色          forState 設定 按鈕點擊前後的狀態   : 下有圖解     UIControlStateHighlighted     UIControlStateSelected     UIControlStateDisabled     UIControlStateNormal          */        // 為按鈕添加一個動作    //  action:  如果點擊的話執行的方法    [self.loginBtn addTarget:self action:@selector(Login:) forControlEvents:UIControlEventTouchUpInside];        //把button控制項添加到view中顯示    [self.view addSubview:self.loginBtn];

 

//執行動作的方法-(IBAction)Login:(id)sender;



 

 

六種定義button類型: 

     UIButtonTypeCustom = 0,   無類型

     UIButtonTypeRoundedRect,   四個角是圓弧  型的   

 

     UIButtonTypeDetailDisclosure    

     UIButtonTypeInfoLight    

 

     UIButtonTypeInfoDark    

 

     UIButtonTypeContactAdd    

 

 

 

 

forState 設定 按鈕點擊前後的狀態   

        點擊前                                         點擊後

UIControlStateHighlighted

 

UIControlStateSelected   

 

UIControlStateDisabled   

 

      UIControlStateNormal     

 

 

 

UIButtonTypeRoundedRect 設定為這個屬性,是可以滿足我們普通情況下的按鈕圓角,當我們在button上添加背景圖片和背景顏色的時候就會發現,這個屬性並不適用,因為現在的button已經不是圓角的了,它顯示的是圖片的形狀,當設定背景顏色設定為UIButtonTypeCustom屬性才可以顯示出來。所以我們需要用UIButton控制項的其它屬性來滿足我們的需求

UIButton *btn;    [btn.layer setMasksToBounds:YES];    [btn.layer setCornerRadius:10.0];//設定矩形四個圓角半徑        /*        [btn.layer setBorderWidth:1.0];//邊框寬度     */

 原文:http://blog.csdn.net/like7xiaoben/article/details/7588551

轉-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.