2017-01-16 100 views
0

我設置的按鈕標題和圖像都..但我面臨的問題..我的按鈕標題重疊的圖像。按鈕標題隱藏按鈕圖像的iOS

我的代碼是

-(void)addImageonbtn:(UIButton *)Button{ 
[Button setImage:[UIImage imageNamed:@"drop_bg"] forState:UIControlStateNormal]; 
Button.imageEdgeInsets = UIEdgeInsetsMake(0, Button.frame.size.width, 0, 24); 
Button.titleEdgeInsets = UIEdgeInsetsMake(0, -37, 0, 0); 
Button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft ; 

Button.layer.borderWidth=1; 
Button.layer.borderColor=[UIColor colorWithRed:5/255.0 green:195/255.0 blue:249/255.0 alpha:1.0].CGColor; 
Button.clipsToBounds=YES; 
} 

如何設置圖像在圖像的背景。這裏是問題的圖像 enter image description here

+1

你應創建一個具有UILabel和UIImageView的組件,將UILabel的寬度限制爲UIImageView的起始X,它不會重疊。 – iphonic

回答

0

您需要設置背景圖像來解決重疊標題問題。

[Button setBackgroundImage:[UIImage imageNamed:@"drop_bg"] forState:UIControlStateNormal]; 

希望這會幫助你。

+0

這仍然會重疊圖像.. – iphonic

0

如果使用自動佈局和故事板的Xcode提供按鈕設置,如果你想要的文字和圖片,按鈕組語義力從右到左

音符,如:圖片大小必須我適合與按鈕文本