【发布时间】:2013-12-20 06:09:07
【问题描述】:
我想给我的字符串上色并画成一个矩形,我的代码是
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetTextDrawingMode(context, kCGTextFillStroke);
CGContextSetRGBStrokeColor(context, 210.0/255.0f, 0.0f, 0.0f, 1.0f);
CGContextSetRGBFillColor(context, 192.0/255.0, 0.0/255.0 , 13.0/255.0, 1.0);
UIFont *font = [UIFont @"MyriadPro-Regular" size:20.0];
NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
/// Set line break mode
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
/// Set text alignment
paragraphStyle.alignment = NSTextAlignmentCenter;
NSDictionary *attributes = @{NSFontAttributeName:font,
NSParagraphStyleAttributeName:paragraphStyle};
NSString *string = @"My code";
[string drawInRect:(isPad)?CGRectMake(1.0, 400.0, 270.0, 120.0):CGRectMake(1.0, 150.0, 125, 120) withAttributes:attributes];
但是对应的字符串没有得到想要的颜色[红色]。是否缺少任何属性?
【问题讨论】:
标签: ios7 nsstring core-graphics cgcontext cgcontextref