Ron
Ron

Reputation: 394

how to increase the size of subview of mainview

I have a editor where over UIView I put a label and there is labeltext over the label . Now user can create as many UIView by writing text on UITextView and click on button . Now If I need to edit text , on Tapgesture I get the text and show it on the UITextView and user could edit that text .

Now if a user add more text then I need to increase the width of the subview over which the text will fall after clicking on the submit button . So my question is that is it possible to increase a subview width within a mainview . Here is the code through which I get all the subview from the main view

for (UIView *subview in mainview.subviews)
        {
            if(subview.tag==sender.tag)
            {

                for(UIView *getsusublabel in subview.subviews)
                {

                    if([getsusublabel isKindOfClass:[UILabel class]])
                    {
                        UILabel *subsublabel = (UILabel *)getsusublabel;
                        subsublabel.text=imagelabeltext.text;
                    }

                }
            }
        }

here subsublabel is the label on subview .

Upvotes: 0

Views: 172

Answers (2)

user3228871
user3228871

Reputation: 103

If you want to increase label width according to the text, try this code snippet:

//use this for custom font
CGFloat width =  [label.text sizeWithFont:[UIFont fontWithName:@"ChaparralPro-Bold" size:40 ]].width;

//use this for system font 
CGFloat width =  [label.text sizeWithFont:[UIFont systemFontOfSize:40 ]].width;

label.frame = CGRectMake(point.x, point.y, width,height);

//point.x, point.y -> origin for label;
//height -> your label height; 

Upvotes: 2

Sudershan shastri
Sudershan shastri

Reputation: 720

If you want to change the size of the subview with the text, then you can try the folowing supposing that your subView is a label:

CGSize expectedLabelSize = [yourString sizeWithFont:yourLabel.font 
                    constrainedToSize:maximumLabelSize 
                    lineBreakMode:yourLabel.lineBreakMode];

And you can try it on other subViews accordingly.

Upvotes: 1

Related Questions