Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

vertical center image and text. #17

Merged
merged 2 commits into from
Jan 22, 2017
Merged

Conversation

bestwnh
Copy link
Contributor

@bestwnh bestwnh commented Jan 16, 2017

support vertical center image and text

@benguild
Copy link
Owner

Thanks for contributing your two commits. I cleaned up the other one and merged that. Can you tell us a little bit about this one?

The formulas are a little tricky for aligning the image, and we can't make any drastic changes as it might break support for current applications.

@bestwnh
Copy link
Contributor Author

bestwnh commented Jan 21, 2017

At first, let's make it clean. The code change only effect the situation with text. Nothing change for only image.
screen shot 2017-01-21 at 18 17 29

There are two parts of change, let's focus the second(simple) one.
(frameGuess.height/2.0f)-imageInsetVertical+[image size].height+margin_vertical_betweenTextAndImage
It's the y position for the text. From line 94 we can found out the (frameGuess.height/2.0f)-imageInsetVertical is the y position of the image, so image.y + [image size].height+margin_vertical_betweenTextAndImage is the text.y. I think it's pretty clear, right?

Then to the first part
imageInsetVertical=([image size].height+margin_vertical_betweenTextAndImage+drawnTextSize.height)/2.0f;
I make a graph to make it clear.
screen shot 2017-01-21 at 19 20 56
I change the value of imageInsetVertical, the imageInsetVertical is the inset between image.y and superview.middle(BTW, I don't think imageInsetVertical is a good concept, too complex, but I don't want to change too many codes).
To make the text and image vertical center, it just mean the imageInsetVertical is 1/2 of the height of the dashed line part.

@benguild
Copy link
Owner

Can you post screenshots of the before/after different in effect?

@bestwnh
Copy link
Contributor Author

bestwnh commented Jan 22, 2017

before
screen shot 2017-01-22 at 13 55 16
screen shot 2017-01-22 at 13 57 29

after
screen shot 2017-01-22 at 13 56 20
screen shot 2017-01-22 at 13 58 31

The old version is not compatible with multi line text.

@benguild
Copy link
Owner

Hmm, OK. I think the vertical alignment issue I mentioned in #12 was from something else, but this seems fine, and so I've created #18.

@benguild benguild merged commit f1bcaee into benguild:master Jan 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants