ios開發之UIButton 點擊兩張表徵圖轉換

來源:互聯網
上載者:User

現在想定義一個UIButton, 這個button有兩張圖片, 一張算是背景圖, 另外一張顯示圖片1.         我通過setBackgroundImage設定了背景圖片, 用setImage 來設定顯示圖片  但是因為圖片 大於了我設定的按鈕的大小, 所以顯示出來的效果是圖片 超出了按鈕的架構.....                               第一個按鈕是兩張圖片重疊的時候, 後面兩個是分別單獨載入的時候...          原始碼是這樣的:www.2cto.comUIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];        [btn1 setFrame: CGRectMake(10, 10, 50, 50)];        [btn1 setBackgroundImage:[UIImage imageNamed: @"ui4.png"] forState:UIControlStateNormal];        [btn1 setImage:[UIImage imageNamed:@"icon0.png"] forState:UIControlStateNormal];        btn1.contentMode = UIViewContentModeScaleAspectFill;        [self addSubview: btn1];                UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];        [btn2 setFrame: CGRectMake(65, 10, 50, 50)];        [btn2 setBackgroundImage:[UIImage imageNamed: @"ui4.png"] forState:UIControlStateNormal];        btn2.contentMode = UIViewContentModeScaleAspectFill;        [self addSubview: btn2];                UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];        [btn3 setFrame: CGRectMake(120, 10, 50, 50)];        btn2.contentMode = UIViewContentModeCenter;        [btn3 setBackgroundImage:[UIImage imageNamed:@"icon0.png"] forState:UIControlStateNormal];        [self addSubview: btn3]; 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.