Desmond
Desmond

Reputation: 5001

uiimage position with changing text in uibutton

i need to create a uibutton to activate a dropdown menu with text on left & image on right on the same line with changing texts.

i used the code below to shift the image to right and it works, however the image will bounce left and right or under the text based on the wording of the text.

How can i make sure that the image stays at the same X,Y constantly ?

self.moodBut.titleEdgeInsets = UIEdgeInsetsMake(0, -    
self.moodBut.imageView.frame.size.width-10, 0,  
self.moodBut.imageView.frame.size.width+10);
self.moodBut.imageEdgeInsets = UIEdgeInsetsMake(0,     
self.moodBut.titleLabel.frame.size.width+10, 0, -   
self.moodBut.titleLabel.frame.size.width-10);

enter image description here

enter image description here

Upvotes: 0

Views: 324

Answers (2)

Desmond
Desmond

Reputation: 5001

ok i make found out my mistake

this make my image to stay constantly

self.moodBut.titleEdgeInsets = UIEdgeInsetsMake(0, -25, 0, 0);
self.moodBut.imageEdgeInsets = UIEdgeInsetsMake(0, 125, 0, 0);

Upvotes: 0

Eric Qian
Eric Qian

Reputation: 2256

You set the imageEdgeInsets based on the titleLabel.frame.size which is dynamic depends on the length of the title. So instead of using self.moodBut.titleLabel.frame.size.width, just use some constant value.

Upvotes: 1

Related Questions