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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:09:30+00:00 2026-05-29T07:09:30+00:00

Is there a quick and easy way to resize a UIView after creating it

  • 0

Is there a quick and easy way to resize a UIView after creating it and have its subviews resize also?

I have a custom UIView subclass called AnagramLetter, the implementation and interface code for which is shown below:

@interface AnagramLetter : UIView{
    UILabel *letterLbl;
    UIImageView *letterBG;
}
@property (nonatomic, retain) UILabel *letterLbl;
@property (nonatomic, retain) UIImageView *letterBG;
@end


@implementation AnagramLetter
@synthesize letterLbl,letterBG;

- (id)initWithFrame:(CGRect)frame
{
    frame = CGRectMake(0, 0, 166, 235);
    CGRect lblFrame = CGRectMake(1, 1, 164,164);
    self = [super initWithFrame:frame];
    [self setAutoresizesSubviews:YES];
    if (self) {
        // Initialization code
        letterBG = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"anagram_correct_bg.png"]];
        [self addSubview:letterBG];

        letterLbl = [[UILabel alloc] initWithFrame:lblFrame];
        letterLbl.backgroundColor = [UIColor clearColor];
        letterLbl.textColor = [UIColor blackColor];
        letterLbl.textAlignment = UITextAlignmentCenter;
        letterLbl.numberOfLines = 0;
        letterLbl.minimumFontSize = 50;
        letterLbl.font = [UIFont boldSystemFontOfSize:144];
        letterLbl.adjustsFontSizeToFitWidth = YES;
        [self addSubview:letterLbl];
    }
    return self;
}
@end

When I press a button on my UI, I call a method which generate a list of the above items and populates a UIView along its X axis, creating a UIView for each character in a given string. Before I do this, I get the dimensions of the UIView (called anagramHolder), divided by the number of characters in the word. I then set the bounds/frame of the UIView after it has been initialized but so far there has been no change in the behaviour of the created AnagramLetter views.

Below is the code I use to get the dimensions, change the bounds of the created subclass and add the item to the anagramHolder UIView.

- (void) createAnagram {
    float aWidth = 166.0;
    float aHeight = 235.0;
    CGRect rect = [anagramHolder bounds];

    if (!anagramCreated){
        for (int i=0; i<[word length]; i++) {
            AnagramLetter *a;
            if ((rect.size.width / [scrambled length]) < 166){
                float percentDiff = ((rect.size.width / [scrambled length]) / 166);
                aWidth = (rect.size.width / [scrambled length]);
                aHeight = aHeight * percentDiff;
                CGRect newBounds = CGRectMake(0, 0, aWidth, aHeight);
                a = [[AnagramLetter alloc] initWithFrame:newBounds];
            }
            else { a = [[AnagramLetter alloc] init]; }
            [a setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
            [a setAutoresizesSubviews:YES];

            CGPoint pos;
            pos.x = (i * (rect.size.width / [scrambled length])) + (aWidth/2);
            pos.y = (rect.size.height/2);
            [a setCenter:pos];
            [a.letterLbl setText:[NSString stringWithFormat:@"%c",[scrambled characterAtIndex:i]]];
            a.tag = i;
            [anagramHolder addSubview:a];
            [anagramLetters addObject:a];
            [a release];
        }
    }
    anagramCreated = YES;
    [self getAnagramResult];
}
  • 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-29T07:09:32+00:00Added an answer on May 29, 2026 at 7:09 am

    The easiest way to autoresize subviews of particular view is to set appropriate value of subviews property named autoresizingMask.

    For example,

    UIView *view;
    view.autoresizesSubviews = YES;
    UIView *subview;
    subview.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
    [view addSubview:subview];
    

    From Apple Docs:

    UIViewAutoresizing Specifies how a view is automatically resized.
    
    enum {
        UIViewAutoresizingNone                 = 0,
        UIViewAutoresizingFlexibleLeftMargin   = 1 << 0,
        UIViewAutoresizingFlexibleWidth        = 1 << 1,
        UIViewAutoresizingFlexibleRightMargin  = 1 << 2,
        UIViewAutoresizingFlexibleTopMargin    = 1 << 3,
        UIViewAutoresizingFlexibleHeight       = 1 << 4,
        UIViewAutoresizingFlexibleBottomMargin = 1 << 5 }; 
    typedef NSUInteger UIViewAutoresizing;
    

    More info can be found here: UIView

    P.S. Also I am using autoresizingMask to design my applications both for iPhone and iPad.

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

Sidebar

Related Questions

Is there a quick/easy way to have tabular data and have a button that
For a given form in a database, is there a quick/easy way to find
Is there a quick and easy way to update my LINQ dbml files? Right
Is there a quick and easy way of telling if a table has changed
in C# .net 2.0, is there a quick and easy way to retrieve a
I'm sure there is a quick and easy way to calculate the sum of
Is there an easy (therefore quick) way to accomplish this? Basically just take some
Defining custom components in Facelets is easy and quick but there's one thing I
Is there a quick easy way to write the results from the query below
Is there a quick and easy way to backup both SQL Server 2008 and

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.