Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4569930
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:17:23+00:00 2026-05-21T19:17:23+00:00

I can’t set the title of UIButton using IB as center. My title is

  • 0

I can’t set the title of UIButton using IB as center. My title is multi line.
It is giving like this one
enter image description here

But I want like this one
enter image description here

I have given space in this but I don’t want to do that. As it is not aligned exactly for some cases and I know there is a property of UILabel to set the alignment but I don’t want to write a code for that.. just want to set everything from IB.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T19:17:24+00:00Added an answer on May 21, 2026 at 7:17 pm

    Solution1

    You can set the key path in the storyboard

    Set the text to your multiline title e.g. hello ⌥ + ↵ multiline

    You need to press ⌥ + ↵ to move text to next line.

    enter image description here

    Then add the key path

    titleLabel.textAlignment as Number and value 1, 1 means NSTextAlignmentCenter
    titleLabel.numberOfLines as Number and value 0, 0 means any number of lines

    enter image description here

    This will not be reflected on IB/Xcode, but will be in centre at run time (device/simulator)

    If you want to see the changes on Xcode you need to do the following: (remember you can skip these steps)

    1. Subclass the UIButton to make the button designable:

      import UIKit
      @IBDesignable class UIDesignableButton: UIButton {}
      

    2. Assign this designable subclass to the buttons you're modifying:

    Showing how to change the class of the button using Interface Builder

    1. Iff done right, you will see the visual update in IB when the Designables state is "Up to date" (which can take several seconds):

    Comparing the designable and default button in Interface Builder


    Solution2

    If you want to write the code, then do the long process

    1.Create IBOutlet for button
    2.Write code in viewDidLoad

    btn.titleLabel.textAlignment = .Center
    btn.titleLabel.numberOfLines = 0
    

    Solution3

    In newer version of xcode (mine is xcode 6.1) we have property attributed title
    Select Attributed then select the text and press centre option below

    P.S. The text was not coming multiline for that I have to set the

    btn.titleLabel.numberOfLines = 0

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I run this in a Windows command prompt like I can run it
Can any one help me in sorting this out in sed/awk/perl Input file Start
Can I change the field public virtual ClassOne ClassOne { get; set; } to
Can I authenticate with just Google account username and password instead of using OAuth?
Can any one tell, how to get the result of LINQ query contains group
Can someone thoroughly explain the last line of the following code: def myMethod(self): #
Can anyone explain to me why this program: for(float i = -1; i <
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I want to count how many characters a certain string has in PHP, but
Can PHP PDO extension bind nested objects automatically ? I mean using foreign key

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.