IPhone: Vertically centering UILabel text

The UILabel permits horizontal centering of its text via the textAlignment property, but there seems to be no way to align the text vertically. I have 3 labels, the last holding from one line to several. It if only has a single line, the text is vertically centered giving a big gap from he previous text. That looks uncool. (and in the Mac world, cool is everything). Is there some secret magical way to get UILabel to vertically center is text as well, or do I need to abandon labels and just drop down to drawRect.

Check out NSString(UIStringDrawing). It has the following method, which you can use to calculate the size of the text as it would be in the label. Then you can set the label height to the minimum necessary for the text, which will solve your vertically centering problem.
sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:

Similar Messages

  • Vertically Centering Dynamic Text

    I am trying to get the text I am loading into a dynamic text
    box vertically aligned. There are from 3 to 8 lines of text that
    load into the dynamic text box via an array. I haven't found
    anything to do this. Can I get a coordinate that tells me the
    height of the loaded in text? Thanks for any help...

    I have the answer to my own question....
    placeText = function(){
    //this first line just creates a variable with the button
    number pushed
    var currentButton = _parent._parent.buttNo;
    //oBox_txt is my dynamic text box
    oBox_txt.autoSize = "center";
    //this line populates the text box with text from an array
    using the predefined
    //variable "currentButton"
    oBox_txt.text = textual[currentButton];
    oBox_txt._y = ((100 - oBox_txt._height) / 2);
    This assumes that the box is at the _y coordinate 0, and that
    the box is 100 pixels high.

  • Vertical Centering of a page in GoLive

    I need a help in vertical centering a page. After long trials and with the help of others in this forum I was able a website that is functioning well enough. The only concern is that it needs to be centered vertically. You can see the website on: http://www.chimeddorj.com
    I read the tutorial on the following link, and I liked the 3rd method.
    http://blog.themeforest.net/tutorials/vertical-centering-with-css/
    But it was too complicated for me as I don't use GoLive often enough. I made this website 3 months ago and since then I haven't used it again. As a result I kind of forgot a lot of things that I knew at that time. If you know how to make the Vertical Centering, could you please guide me how to place the codes in right places? I could provide you with necessary files if necessary. You can also see the HTML code sources by clicking the right button on the website that I created. 
    For some people it may be easy as click. Please help me if you can.

    Thank you very much for comment. I tried to use the table method with your codes. It is centering the content horizontally, but not vertically. The contents are stuck to the top as I resize the window. It seems like I am missing some point. I copy and paste my current code. Could you please give me more advice?
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <meta name="generator" content="Adobe GoLive" />
    <title>Mongolian Artist Chimeddorj</title>
    <script src="js/swfobject.js" type="text/javascript" ></script>
    <style type="text/css" media="screen"><!--
    body { text-align: left; }
    a:link { color: silver; font-size: 14px; font-family: Helvetica, Geneva, Arial, SunSans-Regular, sans-serif; font-weight: 600; font-stretch: condensed; line-height: 18px; text-decoration: none; }
    a:visited { color: silver; font-size: 14px; font-family: Helvetica, Geneva, Arial, SunSans-Regular, sans-serif; font-weight: 600; line-height: 18px; text-decoration: none; }
    a:hover { color: black; font-size: 14px; font-family: Helvetica, Geneva, Arial, SunSans-Regular, sans-serif; font-weight: 600; line-height: 18px; text-decoration: none; }
    a:active { color: gray; font-size: 14px; font-family: Helvetica, Geneva, Arial, SunSans-Regular, sans-serif; font-weight: 600; line-height: 18px; text-decoration: none; }
    #Name { color: #633; font-size: 14px; font-family: Helvetica, Geneva, Arial, SunSans-Regular, sans-serif; font-weight: 600; text-decoration: none; }
    .note { color: gray; font-size: 11px; font-family: Helvetica, Geneva, Arial, SunSans-Regular, sans-serif; line-height: 15px; }
    --></style>
    </head>
    <body>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" height="100%">
                    <tr align="center" valign="middle">
                        <td align="center" valign="middle">
    <div style="position:relative;width:1060px;height:540px;-adbe-g:p;">
    <div style="position:absolute;top:0px;left:0px;width:700px;height:540px;-adbe-c:c">
    <script type="text/javascript">
    var flashvars = {XMLFile: "paintings.xml"};
    var params = {bgcolor: "#ffffff", allowFullScreen: "true"};
    swfobject.embedSWF("ArtFlashGallery.swf", "myAlternativeContent","700", "540", "10.0.0",false, flashvars, params);
    </script>
    <div id="myAlternativeContent">
    <a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /> </a></div>
    <br />
    <!-- You can't remove the copyright text below if you're using free version --></div>
    </div>
    </td>
    </tr>
    </table>
    </body>
    </html>

  • Centering Imported Text

    Hi,
    I am importing a few thousand lines of text  via variable/datasets from a csv on cs4.
    This text varies in length from a few lines long up to almost a dozen.
    The import is working fine, however is there any way of centering the text vertically with the text paragraph box upon import?
    I really dont want to have to go through every exported psd and manually reposition.
    Any Idea?
    Cheers
    P.Pop

    Add line-height: 36px; to your 'tracks' class css, as below:
    .tracks {
        font-family: "Goudy Old Style";
        color: #000;
        padding-left: 120px;
        margin-top: 60px;
    line-height: 36px;

  • Vertically center live text

    Since the anchor point of live text is normally at the baseline, vertically centering text using %age of comp doesn't work.
    It doesn't seem that dividing the text point size by 2 gives me a correct vertical offset either (which should work if my text size was the caps height, right?). So AE must be using the X-height as the font size?  So I have no idea what the X-height for some fonts are.
    Other than visually manually adjusting the anchor point or the baseline offset, is there any better/quicker/automated way of vertically centering text within a comp?

    Hey Navarro, I understand your pain
    I've used a workaround, not automated but it helped me anyway. You'll have to do this for every font you wanna use.
    1) Create a new comp, standard HD for exemple and write a text with your font in size 20.
    2) Now use the region of interest to match exactly the size of your text (well the height at least).
    3) In the comp menu, use the crop to region of interest button. Co to the comp setting and write down the height.
    4) Now redo the 3 first steps with size 60.
    5) then all you'll have to do is a little rules of 3 to automagically calculate the actual X-size depending on the size of your font, and write down an expression for this on your anchorPoint.
    A bit PITA, but it has worked great for me.
    Hope that helps.

  • How do I convert my Voice Memo from iPhone 5s to a text file?

    How do I convert my Voice Memo from iPhone 5s to a text file?

    If you have Evernote, you could try quicktate.   http://www.quicktate.com
    I convert voice memos on my Mac using the Dictation feature:
    Open TextEdit on a new document
    Enable  Dictation & Speech enabled the System Preferences.
    Press the fn-key twice
    Play the voice memo on the iPhone and let the  Mac listen to it using the internal microphone with TextEdit open on a new document.
    Press the fn-key twice, to finish Dictation.  You will only see the transcribed text, when Dictation has finished.

  • TS2755 Iphone 4s voice to text messaging has stopped working. Any information on how to correct this?

    Iphone 4s voice to text messaging suddenly stopped working. The little dots that appear while program is preparing to tranfer audio to text shake side to side and no text appear.

    Any ideas on how to fix this problem
    Depends on what the problem is.

  • I have an iphone 4s and the text i send to a friend with a galaxy 4s he is not receiving any help?

    i have an Iphone 4S and the text i send to a friend with a galaxy 4s he is not receiving. Any help?

    Then it's sending as SMS and not iMessage (that's good) so deleting the contact probably didn't help. It also seems iMessage isn't redirecting his texts as he's not used and apple device on the account previously. Can he receive a picture message from you instead? Does he receive texts from other  apple devices? (iPhones,pods/pads) try sending a text through Verizon online using your account on a web browser. If it is also blocked then it confirms the issue is with his device, well at least points you there rather than guessing if it's yours or his or both. There's some ideas, let me know- Joe
    Sent from my iPhone

  • How can I make a title (text) on a postcard vertical not horizontal text?

    How can I make a title (text) on a postcard layout vertical not horizontal text?

    Insert it in a Text Box then rotate this one.
    Yvan KOENIG (VALLAURIS, France) lundi 13 juin 2011 16:20:28
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.7
    Please : Search for questions similar to your own
    before submitting them to the community
    To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer !

  • After upgrading to iOS 5 my music crash when i turn the iphone vertical to horizontal !!

    after upgrading to iOS 5 my music crash when i turn the iphone vertical to horizontal !!

    I am having this same issue.

  • Problem with non iPhone users receiving my text sent pictures. Can I make them smaller files?

    Problem with non iPhone users receiving my text sent pictures.  Can I make them smaller files? I know that is possible for email sent pics.

    My bad,  It was a Verizon problem.  When they upgraded my phone they were supposed to remove all blocks on messaging . Found out they did not do this.  All messaging now works.  Thanks for listening.

  • My iPhone 4 is sending texts from my email!! Error message near phone number!

    My iPhone 4 is sending texts from my email and when I go into the settings to fix this it says "Error" next to my phone number and will not allow me to select it to send/receive texts from. So people are telling me they are texting me but I have not received them and they are telling me that I am sending mesages from my email. Please Help!

    Open Settings.
    Go to Messages > Send & Receive.
    Select or unselect as you please.
    Tip: You can un-check your emails if you don't want to send or receive using your email.

  • I dropped my iphone vertically on the ground. The screen is normal when it is locked. but when unlocked, it is broken down from the clock. Can it be fixed and is it under the warranty conditions? If not how much is the price to change the screen?Thanks

    I dropped my iphone vertically on the ground.The screen works when it is locked.When unlocked, it's broken down from the clock.Can it be fixed and is it under warranty conditions?If not how much is the price to change the screen?Thanks

    User damage is not covered by warranty unless you have Applecare +
    assuming you do not,  the out of warranty exchange price for an iPhone 4 is $149,exchange at an Apple Store genius bar
    iPhone 4 are not repaired they are exchanged

  • Why is vertical centering still such a challenge?

    Is it really still this tricky to code DW to allow easy vertical centering? Just wondering. Tools for web design have been around long enough, and yet, simply vertically centering an image remains... elusive. Sure - if you know exactly how to do it, or remember it, or figure it out.... sometimes I can get it to work with relative ease; other times, not so much.
    Really, though - no vertical center button anywhere?  (I may have missed it.)
    Now, I admit, I have some homework to do; in the mean time, though, is there any guide someone can recommend?
    I'd like to both center divs vertically as well as center their content vertically, and not necessarily both at the same time... preferably using css.
    thanks,
    Andrew

    as to why this is this case is presumably because as the width of an element shrinks, margins-top and position-top and height are contingent on that allowed width.  But margin-top and margin-bottom by default are set to auto. This may make it seem like vertical alignments should occur naturally, but it does not. This is because behind the scenes auto is converted to 0. Meaning that Height auto is automatically set to 100% of its containers height leaving no room for margin-top or margin-bottom.  Vertical formatting of block level normal flow elements, relies on a calculation much like horizontal formatting.  margin-top+border-top+padding-top+height+padding-bottom+border-bottom+margin-bottom must equal its parenting elements height.    However if you use absolutely positioned elements, then if all three of 'top', 'height', and 'bottom' are not auto: If both 'margin-top' and 'margin-bottom' are 'auto', solve for  top+ margin-top+border-top+padding-top+height+padding-bottom+border-bottom+margin-bottom +bottom must equal its parenting elements height. Therefore, margin-top and margin-bottom will be equal values thus vertically centering the element.

  • How do I vertically align my text to center within a div?

    any solutions?

    nevermind I found a way to do it. It's probably not the most efficient way but since I only have a single line of text within the div I managed to vertically center the text using line height. I am new to web design and have been studying and watching tutorials for the last month on dreamweaver. I am getting better but I must say dreamweaver is quite glitchy when it come to accurately displaying the actual design of the webpage in split view. Only when I view my work in line view can I actually see what is really going on.

Maybe you are looking for