2015-04-02 51 views
0

嗨我有一個簡單的應用程序,我應該根據其超級視圖更改UIButton的框架,並基於其框架的標題大小應該得到改變。UIButton的文本不居中

我使用Autolayout來更改該UIButton的框架。但不知道如何改變該UIButton的字體大小。

Landscape mode, working as expeted Portrait mode, the size of font and button s getting changed but the contents are not centered. This is my issue

這是到目前爲止,我已經嘗試了代碼。

1. [self.cButton sizeToFit] ; 

2. [self.cButton.titleLabel sizeToFit] ; 

3. self.cButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter ; 

4. self.cButton.titleLabel.adjustsFontSizeToFitWidth = YES; 

5. self.cButton.titleLabel.textAlignment = NSTextAlignmentCenter ; 

6. self.cButton.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0); 

就像我試過很多東西。

任何人都可以告訴我,如果我在這裏失去了一些東西,我做錯了什麼。

+0

請提供明確的問題陳述。究竟期望的結果是什麼?你發佈的兩個屏幕截圖是正確的還是錯誤的?這些與你的標題中的「居中」有什麼關係? – matt 2015-04-02 20:07:29

+0

你嘗試過contentVerticalAlignment嗎? – 2015-04-02 20:08:13

+0

我做到了,但這並不重要,因爲它垂直居中。 – 2015-04-02 20:09:41

回答

0

我有這個問題,事實證明,我是凌駕layoutSubviews,忘記打電話[super layoutSubviews]