-(UIImage *)imageFromText:(NSString *)text width:(float)width height:(float)height
{
// set the font type and size
UIFont *font = [UIFont systemFontOfSize:12.0];
CGSize size = CGSizeMake(width, height);// [text sizeWithFont:font];
// check if UIGraphicsBeginImageContextWithOptions is available (iOS is 4.0+)
if (UIGraphicsBeginImageContextWithOptions != NULL)
UIGraphicsBeginImageContextWithOptions(size,NO,0.0);
else
// iOS is < 4.0
UIGraphicsBeginImageContext(size);
// optional: add a shadow, to avoid clipping the shadow you should make the context size bigger
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetShadowWithColor(ctx, CGSizeMake(1.0, 1.0), 5.0, [[UIColor grayColor] CGColor]);
// draw in context, you can use drawInRect/drawAtPoint:withFont:
//[text drawAtPoint:CGPointMake(0.0, 0.0) withFont:font];
[text drawInRect:CGRectMake(0, 0, width, height) withFont:font];
// transfer image
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
[image retain];
UIGraphicsEndImageContext();
return image;
}
- 浏览: 72921 次
- 性别:
- 来自: 成都
相关推荐
###iOS条形码和二维码的生成 ###条形码: ###导入头文件: #import "UIImage-NKDBarcode.h" #import "NKDCode128Barcode.h" 生成条形码的Image NSString *codeStr = @"90876543212276"; UIImage *barImage = [UIImage ...
iOS开发之UIlabel多行文字自动换行 (自动折行) UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(10, 100, 300, 180)]; UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, 300, ...
iOS7.0之后可以利用系统原生 API 生成二维码, iOS8.0之后可以生成条形码, 系统默认生成的颜色是黑色. 在这里, 利用以下方法可以生成指定...+ (UIImage *)qrCodeImageWithContent:(NSString *)content codeImageSize:(C
UIImage *image = [UIImage imageNamed:string]; // 将图片加入数组 [array addObject:image]; } // 1.3把数组存入UIImageView中 self.imageView.animati // 1.4 option self.imageView.animati // ...
IOS 创建彩色二维码 因为系统创建的二维码默认都是黑色的,所以突然想改变一下二维码颜色,具体...+ (UIImage *)createQRCode:(NSString *)string andSize:(CGSize)size andColor:(UIColor *)color { UIImage *qrco
+ (UIImage *)createQRCodeWithString:(NSString *)QRStering withImgSize:(CGFloat)imageFloat; 1.2 方法实现 /** 生成二维码 QRStering:字符串 imageFloat:二维码图片大小 */ + (UIImage *)...
现在越来越多的App添加了一个扫码的功能,方便而且很实用,但是目前对弈iOS来说有些比较知名的库(比如ZXingObjC)库都比较大,而实际上,在iOS 7.0之后系统在AVFoundation框架中就已经实现了对于二维码扫描和生成的...
//CGAffineTransformMakeRotation 方法的作用就是传进去一个角度(计量单位不是度,是弧度),方法内部帮你生成一个这个角度所对应的旋转矩阵 //rotate 旋转 CGAffineTransform a = ...
static NSString *customReuseIndetifier = @"customReuseIndetifier"; CusAnnotationView *annotationView = (CusAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:customReuseIndetifier...
将字符串生成二维码。能够将一个字符串(NSString)转换成一个二维码图像(UIImage)。代码中用到了类库libqrencode。 注意:请在Mac下解压使用