码迷,mamicode.com
首页 > 其他好文 > 详细

drawRect方式画标签

时间:2015-09-06 18:13:27      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

if ([_info[@"cashBack"] floatValue] > 0) {

            

            y += 10.0;

            

            // 离店返金额说明

            UILabel *cashBackLabel = [TRIPLabelFactory createLabelWithText:[[NSString stringWithFormat:@"¥%0.2f",[_info[@"cashBack"] floatValue]/100.0] hotelPriceFormat]

                                                                     color:LABEL_RED

                                                                  fontSize:10

                                                                labelStyle:LabelStyleSolid];

            CGSize labelTextSize = [cashBackLabel.text calculateSizeWithFont:cashBackLabel.font];

            text = [[NSString stringWithFormat:@"入住离店后再返¥%0.2f信用住酒店红包",[_info[@"cashBack"] floatValue]/100.0] hotelPriceFormat];

            size = [text calculateSizeWithFont:TEXT_FONT constrainedToSize:CGSizeMake([UIScreen mainScreen].bounds.size.width-15.0-5.0-cashBackLabel.width, 1000)];

            if (!onlyHeight) {

                // 画标签

                [LABEL_RED set];

                CGContextRef context5 = UIGraphicsGetCurrentContext(); //设置上下文

                CGContextSetLineWidth(context5, 1.0);

                CGContextSetRGBStrokeColor(context5, 0.8, 0.1, 0.8, 1);

                CGContextFillRect(context5, CGRectMake(x, y+(size.height-cashBackLabel.height)/2.0, cashBackLabel.width, cashBackLabel.height));

                // 画标签文案

                [[UIColor whiteColor] set];

                [cashBackLabel.text drawInRect:CGRectMake(x+(cashBackLabel.width-labelTextSize.width)/2.0, y+(size.height-cashBackLabel.height)/2.0, cashBackLabel.width, cashBackLabel.height) withFont:cashBackLabel.font];

                

                [TITLE_TEXT_COLOR set];

                [text drawInRect:CGRectMake(x+cashBackLabel.width+5.0, y, size.width, size.height) withFont:TEXT_FONT];

            }

            y += size.height;

        }

drawRect方式画标签

标签:

原文地址:http://www.cnblogs.com/ranger-jlu/p/4786581.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!