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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:22:28+00:00 2026-05-25T10:22:28+00:00

Hello friends, This is below my code. @interface DynamicLabel : UILabel { } –

  • 0

Hello friends,

This is below my code.

         @interface DynamicLabel : UILabel

      {

      }

         - (id) getSize:(NSString *)text FontName:(NSString *)f_name FontSize:(float)f_size label:  (UILabel *)templbl;

     @end


      #import "DynamicLabel.h"

      #define DEFAULT_COLOR [UIColor blackColor] 

      @implementation DynamicLabel


      - (id)initWithFrame:(CGRect)frame 
     {
        if ((self = [super initWithFrame:frame])) 
     {

         }
         return self;
    }

    //function for dynamically get size of label 
     - (id) getSize:(NSString *)text FontName:(NSString *)f_name FontSize:(float)f_size label:(UILabel *)templbl
     {
         templbl.numberOfLines = 0;
         [templbl setFont:[UIFont fontWithName:f_name size:f_size]];
         [templbl setLineBreakMode:UILineBreakModeWordWrap];

         CGSize maximumLabelSize = CGSizeMake(310,9999);

         CGSize expectedLabelSize = [text sizeWithFont:templbl.font
                                constrainedToSize:maximumLabelSize 
                                                 lineBreakMode:templbl.lineBreakMode];

         CGRect newFrame = templbl.frame;
         NSLog(@"New Frame:--->%@",NSStringFromCGRect(newFrame));
         newFrame.size.height = expectedLabelSize.height;
         NSLog(@"New Frame Height:--->%f",newFrame.size.height);
         templbl.frame = newFrame;
         NSLog(@"Temp Label Frame:--->%@",NSStringFromCGRect(templbl.frame));
         [templbl setText:text];
         NSLog(@"Temp Label Text:---%@",templbl.text);
         [templbl sizeToFit];

         return templbl;
       }

I used above code in RootViewController and success dynamically get height of label

      #import "DynamicLabel.h"

      @interface RootViewController : UIViewController 
     {
       DynamicLabel *dlabel;    
     }

     @property (nonatomic,retain) DynamicLabel *dlabel;

     -(void)dynamiclabel;

     @end

        #import "RootViewController.h"
        #define LABELS_FONT_NAME_BOLD @"Helvetica-Bold"

        #define FONT_GREEN_COLOR [UIColor colorWithRed:0.122f green:0.416f blue:0.20f alpha:1.0f]

        @implementation RootViewController
        @synthesize dlabel;

        #pragma mark -

        #pragma mark View lifecycle


        - (void)viewDidLoad {
           [super viewDidLoad];
       self.title = @"Label Navigation Demo";
        }

        -(void)dynamiclabel
       {
         dlabel = [[DynamicLabel alloc] initWithFrame:CGRectMake(30, 130, 300, 20)];

        [dlabel getSize:@"Choose a topic from the left to find answers for your questions about iPhone. For the latest downloads, manuals, and other resources for iPhone, choose an option below."  
FontName:LABELS_FONT_NAME_BOLD FontSize:12.5f label:dlabel];
        dlabel.textColor = FONT_GREEN_COLOR;
        dlabel.backgroundColor = [UIColor clearColor];
        NSLog(@"Dynamic Label Height:--->%f",dlabel.frame.size.height);
            [self.view addSubview:dlabel];
        }

My issue is that I want to add custom button dynamically wherever iPhone text is displayed in label text. Is there any way to develop this functionality?

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-25T10:22:28+00:00Added an answer on May 25, 2026 at 10:22 am

    You can create custom sized buttons for an arbitrary paragraph of text using stretchable images and sizeWithFont:constrainedToSize:, but a design that needs explanation is not a good design, and a paragraph inside a button is a good example of that.

    enter image description here

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

Sidebar

Related Questions

Hello friends I am using this code in my view.. Using this code I
Hello friends i am running code given below which contains the setLogTimeEntery function and
hello friends i am using this galleria gallery link to display images on my
Hello future friends who is gonna help me big time on this project, I
Hello my smart friends i have this contact form that i am working on.
Hello friends a newbie question... The Issue is like this: I have a static
Hello friends, I have a string like /Date(1312628727617+0000)/ and this regular expression convert into
Hello can anybody solve this please I'm creating the object in the action class
Hello I am working with a simulator that uses rcS scripts to boot, this
hello friends i have created a UDP chatting program through which the clients can

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.