ios sdk 给我们提供了丰富的字体,我们通过枚举可以打印出字体的名字。
for (NSString *familyName in [UIFont familyNames])
{
NSLog(@"font family = %@",familyName );
for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
NSLog(@"\t %@",fontName );
}
}
下面我们绘制一个褐色的hello文本!在view上
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
NSString *attrString =@"hello";
UIColor *stringColor = [UIColorcolorWithRed:0.5fgreen:0.0fblue:0.5falpha:1.0]; //设置文本的颜色
NSDictionary* attrs =@{NSForegroundColorAttributeName:stringColor,
NSFontAttributeName:[UIFontfontWithName:@"AmericanTypewriter"size:18],
}; //在词典中加入文本的颜色 字体 大小
// [attrString drawAtPoint:CGPointMake(100, 100) withAttributes:attrs ]; //根据坐标点画在view上
[attrString drawInRect:CGRectMake(150,120,100,200)withAttributes:attrs]; //给文本限制个矩形边界,防止矩形拉伸;
}
绘制图像和文本用的一个函数
UIImage *image = [UIImageimageNamed:@"see.jpg"];
//[image drawAtPoint:CGPointMake(20, 100)];
[image drawInRect:CGRectMake(40,60,80,80)];