A
A
artursk2016-05-06 18:12:36
Objective-C
artursk, 2016-05-06 18:12:36

How to align the left edge of the title to the center of the button?

There are buttons that contain pictures and titles. Titles with different number of characters. Since initially the title can be set at the left edge of the button, the right edge and the middle of the button, due to the different length of the title in the buttons, the text is not displayed exactly relative to each other, which entails a shift in pictures.
I'm trying to align the text and picture of each button in the storyboard using the tyka adjusting by mm,
but on one size the phone is displayed perfectly evenly, but on other sizes everything floats ... It would be logical to tie the left edge of the title in each button to the middle of the button, and not the entire title to the middle ... Tell me how to do it ? Or are there any other options?
Screenshots to the question at the link, I publish the question from my mobile phone, I can’t upload screenshots:https://forum.swiftbook.ru/t/kak-vyravnit-levyj-kr...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
German Polyansky, 2016-05-06
@artursk

The answer above, as I think it is kostilMaking ...
I have it implemented like this:

- (void)makeContentButtons:(UIButton *)button {
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    button.contentEdgeInsets = UIEdgeInsetsMake(0, 70, 0, 0);
}

This code sets the left alignment and moves the title to the right by 70 floats.
In your case, you can take the length of the button and divide it in half, and you will have the center of the button, which you will write in place of my "70".
I'm attaching a screenshot of the storyboard, and the location of the elements too:
UIButton is highlighted in blue, the text on it is UIButtonLabel, the picture is a simple UIImageView

M
ManWithBear, 2016-05-06
@ManWithBear

Not quite sure what you have there.
But the first thing that comes to mind is to abandon the buttons, push the table there, build the cells normally, and catch the click on the cells of the table.
Another option is custom buttons with their own layout.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question