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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:50:33+00:00 2026-06-18T02:50:33+00:00

I am trying to create a custom UIButton which extends from UIButtonType.RoundedRect . My

  • 0

I am trying to create a custom UIButton which extends from UIButtonType.RoundedRect.

My added functionality is working, but there is an issue with the initial rounded border state of my button. The border of my extended button is not drawn until after it has been tapped.

Before-After Screenshot

Update (January 24th 2013): Added the result of red background test, as requested by Richard Marskell, which concludes only the label of the button is drawn. BackgroundColor = UIColor.Red;

Red Background Test, Before-After Screenshot

Below is my source code for creating my custom button.

public class TestView : UIView
{
    public TestView(IntPtr p) : base(p) { }

    public TestView(RectangleF bounds)
    {
        Frame = bounds;
        BackgroundColor = UIColor.White;

        UIButton button1 = new UIButton(UIButtonType.RoundedRect);
        button1.Frame = new RectangleF(20,20,100,50);
        button1.SetTitle("Button 1", UIControlState.Normal);
        AddSubview(button1); // Drawn Correctly

        MyButton button2 = new MyButton();
        button2.Frame = new RectangleF(20,90,100,50);
        button2.SetTitle("Button 2", UIControlState.Normal);
        AddSubview(button2); // Only drawn correctly after Tap

        // EDIT: Added to test Miguel's theory
        UIButton button3 = UIButton.FromType(UIButtonType.RoundedRect);
        button3.Frame = new RectangleF(20,160,100,50);
        button3.SetTitle("Button 3", UIControlState.Normal);
        AddSubview(button3); // Drawn Correctly
    }
}

public class MyButton : UIButton
{
    public MyButton() : base(UIButtonType.RoundedRect) { }
}
  • I’m just not sure how to force the border to be drawn correctly on loading of the view.
  • I don’t need a button of type UIButtonType.Custom, as I don’t want to style the button myself.
  • When I debug I the type of MyButton is correctly set to UIButtonType.RoundedRect.
  • The UIButton base properties of MyButton (button2) match the properties of the UIButton instance (button1).

Debug

How can I resolve this issue?


Update (January 31st 2013): Herman Schoenfeld provided a suitable solution for this bug.

  • 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-18T02:50:35+00:00Added an answer on June 18, 2026 at 2:50 am

    This works

    public class MyButton : UIButton
    {
        public MyButton() : base(UIButtonType.RoundedRect) { }
    
    
        public override RectangleF Frame {
            get {
                return base.Frame;
            }
            set {
                var temp = TranslatesAutoresizingMaskIntoConstraints;
                TranslatesAutoresizingMaskIntoConstraints = false;
                var constraints = new [] {
                    NSLayoutConstraint.Create(this, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1.0f, value.Width),
                    NSLayoutConstraint.Create(this, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1.0f, value.Height)
                };
                AddConstraints(constraints);
                SizeToFit();
                RemoveConstraints(constraints);
                base.Frame = value;
                TranslatesAutoresizingMaskIntoConstraints = temp;
            }
        }
    }
    

    This is only a workaround, it appears to be a bug. The SizeToFit() fixes the issue, the other code maintains the frame.

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

Sidebar

Related Questions

I'm trying to create custom attributes to my button but I dont know which
I'm trying to create a custom UIButton that should look like a UIButtonTypeRoundedRect. In
I'm trying to create a custom TabItem that is dynamically added to a TabControl
I am trying to create a custom popup view that can be called from
I'm trying to create a custom usercontrol that acts like a button, but i
My application is trying to create custom objects from NSImage objects (coming from the
I'm trying to create an image for a custom style UIButton using an image
I'm trying to create jQuery UI buttons with custom icons, of different sizes from
I'm trying to create custom layout for android. It normally draws on screen, but
I am trying create my custom Style spinner with help of this site. But

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.