开发者

Draw UILabel depends upon string in DrawRect method

In my application I want to draw UILabel dynamically depends upon string in DrawRect method...开发者_运维知识库How can draw this?


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


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. :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜