开发者

Draw UILabel depends upon string in DrawRect method

开发者 https://www.devze.com 2023-03-09 17:55 出处:网络
In my application I want to draw UILabel dynamically depends upon stringin DrawRect method...开发者_运维知识库How can draw this? You want to change the UILabel frame according to your textSize?? If so

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

精彩评论

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