第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在代碼中為UIButton設(shè)置圖像

在代碼中為UIButton設(shè)置圖像

拉莫斯之舞 2019-11-25 14:16:41
如何在代碼中為UIButton設(shè)置圖像?我有這個(gè):UIButton *btnTwo = [UIButton buttonWithType:UIButtonTypeRoundedRect]; btnTwo.frame = CGRectMake(40, 140, 240, 30);[btnTwo setTitle:@"vc2:v1" forState:UIControlStateNormal];[btnTwo addTarget:self action:@selector(goToOne) forControlEvents:UIControlEventTouchUpInside];[self.view addSubview:btnTwo];但看不到將為其設(shè)置圖像的內(nèi)容。
查看完整描述

3 回答

?
月關(guān)寶盒

TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超5個(gè)贊

目標(biāo)C


UIImage *btnImage = [UIImage imageNamed:@"image.png"];

[btnTwo setImage:btnImage forState:UIControlStateNormal];

斯威夫特4


let btnImage = UIImage(named: "image")

btnTwo.setImage(btnImage , for: UIControlState.normal)


查看完整回答
反對(duì) 回復(fù) 2019-11-25
?
叮當(dāng)貓咪

TA貢獻(xiàn)1776條經(jīng)驗(yàn) 獲得超12個(gè)贊

Mike的解決方案將僅顯示圖像,但是在按鈕上設(shè)置的任何標(biāo)題將不可見(jiàn),因?yàn)槟梢栽O(shè)置標(biāo)題或圖像。


如果要同時(shí)設(shè)置(您的圖像和標(biāo)題),請(qǐng)使用以下代碼:


btnImage = [UIImage imageNamed:@"image.png"];

[btnTwo setBackgroundImage:btnImage forState:UIControlStateNormal];

[btnTwo setTitle:@"Title" forState:UIControlStateNormal];


查看完整回答
反對(duì) 回復(fù) 2019-11-25
?
蝴蝶不菲

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊

在此之前,我必須根據(jù)圖像幀的大小顯式調(diào)整按鈕幀的大小。


UIImage *listImage = [UIImage imageNamed:@"list_icon.png"];

UIButton *listButton = [UIButton buttonWithType:UIButtonTypeCustom];


// get the image size and apply it to the button frame

CGRect listButtonFrame = listButton.frame;

listButtonFrame.size = listImage.size;

listButton.frame = listButtonFrame;


[listButton setImage:listImage forState:UIControlStateNormal];

[listButton addTarget:self.navigationController.parentViewController 

               action:@selector(revealToggle:) 

     forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *jobsButton = 

  [[UIBarButtonItem alloc] initWithCustomView:listButton];


self.navigationItem.leftBarButtonItem = jobsButton;


查看完整回答
反對(duì) 回復(fù) 2019-11-25
  • 3 回答
  • 0 關(guān)注
  • 740 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)