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

  • SEARCH
  • Home
  • 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 8253777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:59:29+00:00 2026-06-08T00:59:29+00:00

In iOS, can we set a UIButton and get its width, or must be

  • 0

In iOS, can we set a UIButton and get its width, or must be set its width and then set its content?

It seems that we can

[someString sizeWithFont:someFont].width

to get a width, and then make it the button’s width (by setting its frame) and then set that title and font. But can we just set a button’s font and title (and autosize the button), and then get the width instead?

  • 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-06-08T00:59:31+00:00Added an answer on June 8, 2026 at 12:59 am

    Use the sizeToFit method of UIView (http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/UIView/UIView.html#//apple_ref/doc/uid/TP40006816-CH3-SW11)

    [button setTitle:@"Hello World" forState:UIControlStateNormal];
    [button sizeToFit];
    float width = button.frame.size.width;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an iOS app which can play MIDI and output its content using
I understand that in the Air for IOS settings you can set the Resolution
I am making an AIR for iOS app that can download pdfs. I do
I can detect that app is running under iOS Simulator (using sysctlbyname(hw.machine) ), but
In XCode, for an IOS application target, you can set Version and Build numbers.
In iOS5 we have leftBarButtonItems that we can set to a navigation bar, how
When building a custom frame/view in iOS code, how do you set its rotation
Does anybody know where an iOS app can see the default headers that NSUrlRequest
I want to build an application that can set up a set amount of
Very frustrating experience understanding UIGraphicsPushContext(context) and UIGraphicsPopContext() My understanding is that I can set

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.