-1

In my application I want to draw UILabel dynamically depends upon string in DrawRect method...How can draw this?

Vladimir
  • 170,431
  • 36
  • 387
  • 313
donkarai
  • 322
  • 1
  • 3
  • 14

2 Answers2

0

You want to change the UILabel frame according to your textSize?? If so, refer this post.

Community
  • 1
  • 1
KingofBliss
  • 15,055
  • 6
  • 50
  • 72
0

Try the code below..

It worked for me in the case of button title. :)

CGRect oldLblRect = lbl1.frame;
        lbl1.titleLabel.font = [UIFont systemFontOfSize:15];
        [lbl1 sizeToFit];
        lbl1.frame = CGRectMake(lbl1.frame.origin.x - ((lbl1.frame.size.width - oldLblRect.size.width)/2), lbl1.frame.origin.y - ((lbl1.frame.size.height - oldLblRect.size.height)/2), lbl1.frame.size.width, lbl1.frame.size.height); 

Hope it helps. :)

Shrey
  • 1,959
  • 2
  • 21
  • 44