开发者

place a UIButton named 'Send' after the texView . TextView content will vary in every case depending the xml parsed string

in my application i have a textview . i am displaying some string content in the my textview programmically . I have to place a UIButton named 'Send' after the texView . Means here i am parsing the string content from an xml file . So the string length should vary in every case .

But i have to place a Send button after the textView . How to do it . I found the following code snippet . But sometimes it displayig the send button in position after the textView. Sometimes its not in the position (its overlapping) . help me ...

newsSecondPart is my textView .....

        int secondStringLength = secondStr.length;
        int height = secondStringLength / 48; 
        height = height * 18.0;

           //newsSecondPart is my textView      
           CGRect newsSecondPartFrame = newsSecondPart.frame;

开发者_运维问答    if (height < 400)

      newsSecondPartFrame.size.height = height + 475; // for text unhiding
   else
       newsSecondPartFrame.size.height = height + 975; // for text unhiding

    if (secondStringLength > 5000) {
        newsSecondPartFrame.size.height += 150;
    }


newsSecondPart.frame = newsSecondPartFrame;
    CGRect viewFrame = superView.frame;
    viewFrame.size.height = newsSecondPartFrame.size.height + 200 ;


superView.frame = viewFrame;
    scrollView.contentSize = superView.bounds.size;
scrollView.contentSize = CGSizeMake(    0,  newsSecondPartFrame.size.height+300);


    newsFirstPart.text = firstStr;
    newsSecondPart.text = secondStr;

Please help me .....


To get dynamic size of textview, you need following code

CGSize size = [secondStr sizeWithFont:txtView.font constrainedToSize:CGSizeMake(txtView.frame.size.width,10000)];

size.height +=10;

This way you will get dynamic height of string.

Now you can set frame of textview

CGRect frame = txtView.frame;

frame.size.height= size.height;

txtView.frame = frame;

Now you can set button frame:

CGRect frame = btnSend.frame;

frame.origin.y = txtView.frame.origin.y + txtView.frame.size.height+10;

btnSend.frame = frame;

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜