V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
machinemxy
V2EX  ›  iDev

要是能把 emoji 当成 tabbar 的图标就好了

  •  
  •   machinemxy ·
    machinemxy · 2015-09-21 15:54:09 +08:00 · 2855 次点击
    这是一个创建于 3111 天前的主题,其中的信息可能已经有所发展或是发生改变。

    明明 emoji 里已经有很多优秀的图标了,但是并不能直接把它作为 tabbar 的 image ,还得自己画完再利用工具变为 x1,x2,x3 的尺寸。感觉 emoji 那么多设计精美的图标,应该让它能过发挥更大的作用的。

    4 条回复    2015-09-22 10:45:19 +08:00
    ibremn
        1
    ibremn  
       2015-09-21 16:03:18 +08:00   ❤️ 2
    + (UIImage *)imageWithEmoji:(NSString *)emoji size:(CGFloat )size {
    if (emoji.length == 0 ) return nil;
    if (size < 1 ) return nil;

    CGFloat scale = [UIScreen mainScreen].scale;
    CTFontRef font = CTFontCreateWithName (CFSTR ("AppleColorEmoji"), size * scale, NULL );
    if (!font ) return nil;

    NSAttributedString *str = [[NSAttributedString alloc] initWithString:emoji attributes:@{ (__bridge id )kCTFontAttributeName:(__bridge id )font, (__bridge id )kCTForegroundColorAttributeName:(__bridge id )[UIColor clearColor].CGColor }];
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB ();
    CGContextRef ctx = CGBitmapContextCreate (NULL, size * scale, size * scale, 8, 0, colorSpace, kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst );
    CGContextSetInterpolationQuality (ctx, kCGInterpolationHigh );
    CTLineRef line = CTLineCreateWithAttributedString ((__bridge CFTypeRef )str );
    CGRect bounds = CTLineGetBoundsWithOptions (line, kCTLineBoundsUseGlyphPathBounds );
    CGContextSetTextPosition (ctx, 0, -bounds.origin.y );
    CTLineDraw (line, ctx );
    CGImageRef imageRef = CGBitmapContextCreateImage (ctx );
    UIImage *image = [[UIImage alloc] initWithCGImage:imageRef scale:scale orientation:UIImageOrientationUp];

    CFRelease (font );
    CGColorSpaceRelease (colorSpace );
    CGContextRelease (ctx );
    if (line )CFRelease (line );
    if (imageRef ) CFRelease (imageRef );

    return image;
    }

    加个 Category 到 UIImage 上,随时能把 Emoji 转为 Image ,性能不比直接读取图片差多少。。
    UIImage *image = [UIImage imageWithEmoji:@"😄" size:80];
    machinemxy
        2
    machinemxy  
    OP
       2015-09-21 19:37:54 +08:00
    @ibremn 谢谢!十分好的想法!
    fhefh
        3
    fhefh  
       2015-09-21 20:50:17 +08:00
    mark 收藏~
    parkerjj
        4
    parkerjj  
       2015-09-22 10:45:19 +08:00
    马克一下。。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2926 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 15:15 · PVG 23:15 · LAX 08:15 · JFK 11:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.