技术的乐趣在于分享,欢迎多多交流,多多沟通。
全部博文(877)
分类: iOS平台
2015-11-20 14:57:21
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, INFINITY) options: 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);
}