2016-01-27 37 views

回答

1

當然,在我寫這個問題時,我想起了答案!

一個解決方案:子類UIButton和覆蓋的方法titleRectForContentRectcontentRectForBounds,像這樣:

/// A subclass of UIButton that uses the full bounds of the button for the label (so that text isn't clipped) 
public class FullFrameTitleButton: UIButton { 
    override public func titleRectForContentRect(contentRect: CGRect) -> CGRect { 
     return contentRect 
    } 

    override public func contentRectForBounds(bounds: CGRect) -> CGRect { 
     return bounds 
    } 
} 

的唯一其他剩餘位:中心標題標籤的文本:

let button = FullFrameTitleButton(type: .System) 
button.titleLabel?.textAlignment = .Center 

瞧!沒有更多限制下行: enter image description here