textview's size problem

Discussion in 'iOS Programming' started by electronica, Dec 26, 2011.

  1. electronica, Dec 26, 2011
    Last edited by a moderator: Dec 28, 2011

    electronica macrumors newbie

    Sep 24, 2011
    hi, i have a problem about changing the size of textview.

    UITextView *yazi = [[UITextView alloc] initWithFrame:CGRectZero];
        yazi.text = [NSString stringWithContentsOfFile:hayat encoding:NSUTF8StringEncoding error:nil];
        [yazi setFrame:CGRectMake(0, 245, 320, yazi.contentSize.height)];
    scrollview.contentSize = CGSizeMake(320, yazi.contentSize.height);

    i try to create a textview programatically. Than fill it from different txt files for every row selected in my table. i want to make my scrollview's height equal to textview's height.

    well, basically how can i make a textview's height to fit exactly to the text size.

    thanks for helps.
  2. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    Do you know the superclass of UITextView?

    You can use the methods in UIStringDrawing.h to determine the rectangle that will enclose a text string. sizeWithFont: etc. You can set the frame of your view to the appropriate size based on the result of sizeWithFont:
  3. electronica thread starter macrumors newbie

    Sep 24, 2011
    ok. I'm working on it. i think i can solve this with an easy way.

Share This Page