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
hustlzp
V2EX  ›  iDev

[请教] 请教大家一个问题,为了增加行距,我在 UILabel 的 attributedText 上设置了 lineSpacing ,多行文字没问题,然而单行文字底部会有一个多余的空隙(见图),请问 V 友们知道如何解决吗?

  •  
  •   hustlzp ·
    hustlzp · 2016-03-04 19:00:38 +08:00 · 5030 次点击
    这是一个创建于 2946 天前的主题,其中的信息可能已经有所发展或是发生改变。
    如图:



    谢谢了。
    7 条回复    2016-03-06 23:07:36 +08:00
    dxk611
        1
    dxk611  
       2016-03-04 21:21:54 +08:00
    试下 UILabel 的 baselineAdjustment 属性,现在病榻上,就自己动手试试吧
    hustlzp
        2
    hustlzp  
    OP
       2016-03-04 21:54:08 +08:00
    @dxk611 感谢提醒。祝早日康复。
    hustlzp
        3
    hustlzp  
    OP
       2016-03-04 22:14:38 +08:00
    测试了下,只有中文会有这个问题,英文不会有。

    难怪 Google 不到...
    zenghaojim33
        4
    zenghaojim33  
       2016-03-04 22:15:25 +08:00
    试过 sizeToFit 么
    hustlzp
        5
    hustlzp  
    OP
       2016-03-04 23:07:16 +08:00
    @dxk611
    @zenghaojim33 刚试过了,不行。

    误打误撞解决了,我发现默认 font 为 ST UI Text 。

    然后我强制设置为苹方:

    label.font = UIFont(name: "PingFangSC-Medium", size: 17)

    解决了。
    xi_lin
        6
    xi_lin  
       2016-03-06 14:49:47 +08:00
    @hustlzp 苹方的话 iOS8 就退化回默认字体了吧?
    根据行数来设置 lineSpacing 吧
    hustlzp
        7
    hustlzp  
    OP
       2016-03-06 23:07:36 +08:00
    @xi_lin 恩,有道理。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2843 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 15:22 · PVG 23:22 · LAX 08:22 · JFK 11:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.