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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:33:48+00:00 2026-05-28T04:33:48+00:00

Well, I have some problems with border drawing in UILabel. Here is my snippet

  • 0

Well, I have some problems with border drawing in UILabel. Here is my snippet of code

CGRect frame = CGRectMake(10, 10, 320, 120);
UILabel *label = [[UILabel alloc] initWithFrame:frame];
label.textColor = [UIColor greenColor];
label.font = [UIFont fontWithName:@"Verdana" size:12];
label.textAlignment = UITextAlignmentCenter;
label.text = @"Some text to display"; 
label.layer.backgroundColor = [UIColor cyanColor].CGColor;
label.layer.borderColor = [UIColor redColor].CGColor;
[self.window addSubview:label];
[label release];label=nil;

I have QuartzCore included and I use iOS4.3 When I launch the app in sumulator text is displayed but not the border and background color.
What is wrong here ?

  • 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-28T04:33:48+00:00Added an answer on May 28, 2026 at 4:33 am

    Looking in CALayer.h, we see that the default value for borderWidth is 0.0.

    /* The width of the layer's border, inset from the layer bounds. The
     * border is composited above the layer's content and sublayers and
     * includes the effects of the `cornerRadius' property. Defaults to
     * zero. Animatable. */
    
    @property CGFloat borderWidth;
    

    In order for the border to appear, you must set the borderWidth to something greater than zero.

    You can set the background color on the label directly as so:

    label.backgroundColor = [UIColor cyanColor];
    

    To set a border, you need to set the width, which can be done like so:

    label.layer.borderWidth = 2.0f;
    

    Once you have set a border width, to set the color of the border on the label, you’re setting the view’s layer’s border, which uses a CGColor, so you’ll have to do this:

    label.layer.borderColor = [UIColor redColor].CGColor;
    

    And if you want to round the corners, you can add this:

    label.layer.cornerRadius = 10.0f;
    

    You don’t need to set the background color. You really need to only set the borderWidth and borderColor.

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

Sidebar

Related Questions

I have an application written in C# that invokes some C code as well.
I have some non well-formed xml (HTML) data in JAVA, I used JAXP Dom,
I have a development vm which is running sql server as well as some
I have a settings.php file with parametric variables and a functions.php with well, some
In an ASP.NET 2.0 website, I have a string representing some well-formed XML. I
We'll soon have some high school kids here in our company for some training
I need to scrape some data from webpages. But I have some encoding problems
I have some problems with IntelliJ Idea not copying SQL resource files into target
currently I'm having some problems with my preloader. I have an as3 class website
I have some problems animating a loaded COLLADA Model. I've written my own parser

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.