iOS字体设置常用代码

1060阅读 0评论2015-11-20 jeffasdasd
分类:iOS平台

        CGContextRef context = UIGraphicsGetCurrentContext();

    

//        CGContextAddRect(context, CGRectMake(200, 246, 121, 30));

        //// Text Drawing

        CGRect textRect = CGRectMake(waterX, waterY, waterW, waterH);

        {

            NSString* textContent = @"Hello, World!";

            NSMutableParagraphStyle* textStyle = NSMutableParagraphStyle.defaultParagraphStyle.mutableCopy;

            textStyle.alignment = NSTextAlignmentLeft;

    

            NSDictionary* textFontAttributes = @{NSFontAttributeName: [UIFont systemFontOfSize: UIFont.labelFontSize], NSForegroundColorAttributeName: UIColor.blackColor, NSParagraphStyleAttributeName: textStyle};

    

            CGFloat textTextHeight = [textContent boundingRectWithSize: CGSizeMake(textRect.size.width, INFINITYoptions: NSStringDrawingUsesDeviceMetrics attributes: textFontAttributes context: nil].size.height;

            CGContextSaveGState(context);

    

    //        CGContextAddRect(context, CGRectMake(200, 246, 121, 30));

    

    //        CGContextClipToRect(context, textRect);

            [textContent drawInRect: CGRectMake(CGRectGetMinX(textRect), CGRectGetMinY(textRect) + (CGRectGetHeight(textRect) - textTextHeight) / 2, CGRectGetWidth(textRect), textTextHeight) withAttributes: textFontAttributes];

            

//             CGContextShowTextAtPoint (context, 40, 0, "Quartz 2D", 9);

            

            

//            // 画文字

//            NSString *str = @"的额搜风搜分手了粉色发俄双方说法offFF瓦房你F回复F入会费WFH;飞;FN返回WFH;哦发货;F回复;FHISFHSIFH我皮肤好APIFRHi分红AWFHIOF威锋网i";

//            [str drawInRect:CGRectMake(50, 50, 100, 100) withAttributes:nil];

            

            CGContextRestoreGState(context);

        }

上一篇:iOS boundingRectWithSize:options:attributes:context:计算文本尺寸
下一篇:UIButton文字的一些属性,和font的一些属性