Reputation: 1347
Ha ii everybody,i have a requirement that i have a button in my app with text its text changes dynamically according to different actions on the app,that means if the button title is god on other action it changed to some lengthy text like stack-overflow or something,and i have a small downarrow image on the right side of this button ,like the username that displays in the main header of the stack-overflow,a downarrow on the left-side with the username,like that,but my problem is i put this image in a fixed position the image never changed the position,if the god is the title of the button the image is too far from the button if the text is stack-overflow the image will hide by the text,i need a solution how to auto-adjust the position of the image according to the text length of the button near this image.I hope you genius developers understand my question.Please help me to solve this issue. Thanks in advance.
Upvotes: 0
Views: 106
Reputation: 17478
Find the width of the button text. Set the origin of the image view according to the width.
Upvotes: 0
Reputation: 1433
You can try this
CGSize expectedLabelSize = [buttonText sizeWithFont:button.titleLabel.font constrainedToSize:maxLabelSizeForAdd lineBreakMode:button.titleLabel.lineBreakMode];
CGRect rect = CGRectMake(150, 10, expectedLabelSize.width, expectedLabelSize.height);
Assign this rect to button For image
CGRect rect = CGRectMake(150+button.frame.origin.x+10, height, imageWidth,imageHeight);
Assign this rect to image. In this expectedLabelSize calculates size of string and according to text size you can adjust button position. As I am new to iphone development I hope this will work for you..
Upvotes: 4