开发者

How can i make bold a single character in the lable without using UIWebView?

开发者 https://www.devze.com 2022-12-28 08:19 出处:网络
I have a UILabel which contains textvalue and i want to bold a particular character in that whole string so please let me inform is it possible? and yes then please give me some example it really impo

I have a UILabel which contains textvalue and i want to bold a particular character in that whole string so please let me inform is it possible? and yes then please give me some example it really important f开发者_StackOverflowor me.Please help me.


It's possible as single-line label if you create a custom UIView subclass, and implement the -drawRect: like this:

-(void)drawRect:(CGRect)rect {
   NSString* stringBefore;
   NSString* boldPart;
   NSString* stringAfter;
   UIFont* normalFont;
   UIFont* boldFont;
   ...
   CGSize sizeBefore = [stringBefore drawAtPoint:CGPointZero withFont:normalFont];
   CGSize sizeBold = [boldPart drawAtPoint:CGPointMake(sizeBefore.width, 0) withFont:boldFont];
   [stringAfter drawAtPoint:CGPointMake(sizeBefore.width+sizeBold.width, 0) withFont:normalFont];
}


Sorry, can be done in 3.2 (and higher) with NSAttributedString. But not in the iPhone as it exists today.

0

精彩评论

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

关注公众号