问题
Hello I am creating UIButton
which is displaying image and title at the same time. I want title and image to be both centred, button to be above image. Problem is that because of localisation of string from button, string length is changing, and alignment from UIStoryboard
combined with edge insets is not working as I want it to work. Can someone help me and point me in the right direction?
回答1:
set these two. 1. set Align controls of UIButton
- set Image and Text Inset of UIButton
回答2:
The first thought is that you could build a UIView showing image and text, then attach a UITapGestureRecognizer to it, which would be more flexible than UIButton.
回答3:
I am not sure, but you can try to set title like this:
[someButton setTitle:@"\nsome title" forState:UIControlStateNormal];
where \n
is a new line.
回答4:
Adjust titleEdgeInsets and imageEdgeInsets accordingly
[self.facebookButton setImage:[UIImage imageNamed:@"facebook_icn"] forState:UIControlStateNormal];
[self.facebookButton setTitle:NSLocalizedString(@"Invite via Facebook1",nil) forState:UIControlStateNormal];
self.facebookButton.titleEdgeInsets = UIEdgeInsetsMake(0.0f, 5.0f, 0.0f, -5.0f);
self.facebookButton.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
来源:https://stackoverflow.com/questions/28340575/uibutton-different-alignment-for-title-and-image