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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:12:36+00:00 2026-05-27T17:12:36+00:00

I have a segment of code that gets executed everytime a backend database change

  • 0

I have a segment of code that gets executed everytime a backend database change occurs. Essentially I have a label inside of a parent view. The label gets updated by one of many status messages each one on a different line ended by a new line (\n). Each status message needs to be on one line only and not go over.

The problem I am having is that everything works fine when the View first reloads. However when I am on the screen and a change occurs in background, once in a while a status message displays on multiple lines. While sizeToFit does a great job of making the label as high as the parent containing view, it does so poorly in terms of width. That is it will break up text on multiple lines as opposed to looking at the line breaks only.

What can I do?

self.messageLabel.text = message; //lets get the status message.
        [self.messageLabel sizeToFit];
        [self.messageLabel setNeedsDisplay];
        CGRect frame = [self.messageView frame];
        frame.size.height = self.messageLabel.bounds.size.height;
        self.messageView.frame = frame;
        self.messageLabel.center = CGPointMake(CGRectGetMidX(self.messageView.bounds), CGRectGetMidY(self.messageView.bounds)-(self.messageView.cornerRadius/4));
        self.messageLabel.backgroundColor = [UIColor orangeColor];
        [self.messageView setNeedsDisplay];
  • 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-27T17:12:37+00:00Added an answer on May 27, 2026 at 5:12 pm

    In order to determine the size that your label will need to be, you need to look into the NSString size methods. There’s a number of them that can tell you the size a string will be given a font, and various constraints.

    For example [@"string" sizeWithFont: forWidth: lineBreakMode:]; will return a CGSize that you can then use to size your label appropriately.

    As an aside, I find the UILabel does not handle strings with multiple lines well. You may be better off writing your own subview of UIView that can handle multiple lines of text, each with its own label.

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

Sidebar

Related Questions

I have the following segment of code that someone else has written, and that
Below I have a segment of my code that I recently added to my
I'm finalizing a code segment that lists the files in a directory. I have
I have studied that during a fork, the data and code segment of the
I have a subprocess function (called parseContents) that gets called using the following code:
I have a code segment as below that uses BufferedReader to read inputs from
Hey, I have a code segment here: <div class=label><%= f.label :course %> <span>(Does this
So basically the problem is that I have segment of code that needs to
I have a controller class as in the following code segment: @Controller public class
I have two identical byte arrays in the following segment of code: /// <summary>

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.