我有一个正在用代码绘制的字符串
[@"-"drawInRect: r
带字体:f2
lineBreakMode: UILineBreakModeWordWrap
对齐:UITextAlignmentCenter];
但是我想改变这个字符串中的颜色,因为这对于 NSString 是不可能的,我希望将它修改为一个 NSAttributedString。
但这不起作用,这是我修改后的代码,我也找不到其他参数的属性
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:f2,NSFontAttributeName,
nil];
NSAttributedString *drawingString = [[NSAttributedString alloc] initWithString"-" attributes:attrsDictionary];
[drawingString drawInRect:r];
感谢任何帮助,无论这是否是正确的方法。
谢谢!这是我最终编辑的代码
NSMutableParagraphStyle *paraAttr = [[NSMutableParagraphStyle defaultParagraphStyle ] mutableCopy];
[paraAttr setAlignment:UITextAlignmentCenter];
[paraAttr setLineBreakMode:UILineBreakModeWordWrap];
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:f2,NSFontAttributeName,
[UIColor grayColor],NSForegroundColorAttributeName,
paraAttr,NSParagraphStyleAttributeName,
nil];
NSAttributedString *drawingString = [[NSAttributedString alloc] initWithString"•" attributes:attrsDictionary];
[drawingString drawInRect:r];
关于objective-c - 将 NSString 转换为 NSAttribtuedString 以进行绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12726423/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/) | Powered by Discuz! X3.4 |