首页 文章 精选 留言 我的

精选列表

搜索[特殊字符],共10011篇文章
优秀的个人博客,低调大师

iOS 开发之字符串转图片

UIFont *font = [UIFont fontWithName:@"Menlo" size:12 * 2]; UIImage *wenbenImage = [self imageWithString:Str font:font width:576 textAlignment:NSTextAlignmentLeft]; - (UIImage *)imageWithString:(NSString *)string font:(UIFont *)font width:(CGFloat)width textAlignment:(NSTextAlignment)textAlignment { NSDictionary *attributeDic = @{NSFontAttributeName:font}; CGSize size = [string boundingRectWithSize:CGSizeMake(width, 10000) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine attributes:attributeDic context:nil].size; if ([UIScreen.mainScreen respondsToSelector:@selector(scale)]) { if (UIScreen.mainScreen.scale == 2.0) { UIGraphicsBeginImageContextWithOptions(size, NO, 1.0); } else { UIGraphicsBeginImageContext(size); } } else { UIGraphicsBeginImageContext(size); } CGContextRef context = UIGraphicsGetCurrentContext(); [[UIColor whiteColor] set]; CGRect rect = CGRectMake(0, 0, size.width + 1, size.height + 1); CGContextFillRect(context, rect); NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init]; paragraph.alignment = textAlignment; NSDictionary *attributes = @ { NSForegroundColorAttributeName:[UIColor blackColor], NSFontAttributeName:font, NSParagraphStyleAttributeName:paragraph }; [string drawInRect:rect withAttributes:attributes]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; }

优秀的个人博客,低调大师

Android填坑系列:Android JSONObject 中对key-value为null的特殊处理

在与服务端通过JSON格式进行交互过程中,不同版本的JSON库在对于key-value为null情况上的处理不同。 Android自带的org.json对key-value都要求不能为null,对于必传的字段需要留意一下,尤其是留意value是否可能出现null的情形。否则导致服务端解析出现问题。 此坑已被踩中,留下小记。下面直接看一下相应位置源码: 1 public class JSONObject { 2 3 ...... 4 5 /** 6 * Maps {@code name} to {@code value}, clobbering any existing name/value 7 * mapping with the same name. If the value is {@code null}, any existing 8 * mapping for {@code name} is removed. 9 * 10 * @param value a {@link JSONObject}, {@link JSONArray}, String, Boolean, 11 * Integer, Long, Double, {@link #NULL}, or {@code null}. May not be 12 * {@link Double#isNaN() NaNs} or {@link Double#isInfinite() 13 * infinities}. 14 * @return this object. 15 */ 16 public JSONObject put(String name, Object value) throws JSONException { 17 if (value == null) { 18 nameValuePairs.remove(name); 19 return this; 20 } 21 if (value instanceof Number) { 22 // deviate from the original by checking all Numbers, not just floats & doubles 23 JSON.checkDouble(((Number) value).doubleValue()); 24 } 25 nameValuePairs.put(checkName(name), value); 26 return this; 27 } 28 29 30 String checkName(String name) throws JSONException { 31 if (name == null) { 32 throw new JSONException("Names must be non-null"); 33 } 34 return name; 35 } 36 37 38 ...... 39 40 } --------------------------------------------------------------------------------- 笔者水平有限,若有错漏,欢迎指正,如果转载以及CV操作,请务必注明出处,谢谢! 分类: Android 本文转自Windstep博客园博客,原文链接:http://www.cnblogs.com/lwbqqyumidi/p/5491074.html,如需转载请自行联系原作者

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册