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 6378753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:02:55+00:00 2026-05-25T02:02:55+00:00

I have an NSButton (Push Button) with some temporary title text built in Interface

  • 0

I have an NSButton (Push Button) with some temporary title text built in Interface Builder / Xcode. Elsewhere, the title text inside the button is changed programmatically to a string of unknown length (actually, many times to many different lengths).

I’d like the button to automatically be resized (with a fixed right position–so it grows out to the left) to fit whatever length of string is programmatically inserted as button text. But I can’t figure it out. Any suggestions? Thanks in advance!

  • 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-25T02:02:56+00:00Added an answer on May 25, 2026 at 2:02 am

    If you can’t use Auto Layout as suggested by @jtbandes (it’s only available in Lion), then you can call [button sizeToFit] after setting its string value, which will make the button resize to fit its string. You would then need to adjust its frame based on the new width.

    You can’t do this automatically, but it would be easy to do in a subclass of NSButton.

    @implementation RKSizeToFitButton
    - (void)setStringValue:(NSString*)aString
    {
        //get the current frame
        NSRect frame = [self frame];
    
        //button label
        [super setStringValue:aString];
    
        //resize to fit the new string
        [self sizeToFit];
    
        //calculate the difference between the two frame widths
        NSSize newSize = self.frame.size;
        CGFloat widthDelta = newSize.width - NSWidth(frame);
        //set the frame origin
        [self setFrameOrigin:NSMakePoint(NSMinX(self.frame) - widthDelta, NSMinY(self.frame))];
    }
    @end
    

    This way you can just set your button’s class to RKSizeToFitButton in Interface Builder and then calling setStringValue: on the button to change its label will “just work” with no additional code.

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

Sidebar

Related Questions

I'm making a simple dialog in XCode 4 using the Interface Builder. I have
In my application I have some controls like NSButton and NSTextfield I want to
I have the code #import <Cocoa/Cocoa.h> @interface MyButton : NSButton { } - (void)mouseDown:(NSEvent
Any way to have a NSButton title to wrap when it's width is longer
I have created a simple NSWindow with an NSTextField and an NSButton in Interface
I have an NSButton that I'd like to animate when I call [button setHidden:
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have some data in a sybase image type column that I want to use
I have following requirements: Obtain action associated with NSButton using : - (SEL)action Call
have such zend query: $select = $this->_table ->select() ->where('title LIKE ?', '%'.$searchWord.'%') ->where('description LIKE

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.