2017-04-19 121 views
0

我有一個名爲login的按鈕。當我看到按鈕的字體大小在所有設備中看起來都一樣,雖然按鈕的寬度和高度有所不同。如何爲不同的設備定義不同的字體大小?我只是談論iPhone的肖像。所以不要給解決方案作爲尺寸等級。爲不同的設備設置不同的字體大小到UIButton

+0

您可以使用大小類此。 – KKRocks

+1

[iOS不同設備的單個大小類中的iOS不同字體大小的可能重複](http://stackoverflow.com/questions/28076020/ios-different-font-sizes-within-single-size-class-for-different-設備) – KKRocks

回答

0

您可以使用字體大小變化 - 在Storyboard中定義字體大小,查看下面的圖像,它顯示瞭如何定義字體大小。

enter image description here

點擊除了字體屬性小+按鈕,彈出就會出現。

如上圖所示,您可以根據不同的變化定義尺寸WidthHeight

0

您可以檢查iPhone設備的大小,然後在if-else循環中應用您的按鈕字體大小邏輯。

#define iPhoneVersion ([[UIScreen mainScreen] bounds].size.height == 568 ? 5 : ([[UIScreen mainScreen] bounds].size.height == 480 ? 4 : ([[UIScreen mainScreen] bounds].size.height == 667 ? 6 : ([[UIScreen mainScreen] bounds].size.height == 736 ? 7 : ([[UIScreen mainScreen] bounds].size.height == 736 ? 61 : ([[UIScreen mainScreen] bounds].size.height == 736 ? 61 : (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 10 :61))))))) 

if (iPhoneVersion == 4) 
{ 
    mybutton.titleLabel.font = [UIFont systemFontOfSize:12]; 
} 
else if (iPhoneVersion == 5) 
{ 
    mybutton.titleLabel.font = [UIFont systemFontOfSize:14]; 
} 
else if (iPhoneVersion == 6) 
{ 
    mybutton.titleLabel.font = [UIFont systemFontOfSize:16]; 
} 
else if (iPhoneVersion == 7) 
{ 
    mybutton.titleLabel.font = [UIFont systemFontOfSize:17]; 
} 

對於所有設備也是如此。

0

試試這個

if UIScreen.mainScreen().bounds.size.height == 480 { 
    // iPhone 4 
    mybutton.titleLabel.font = mybutton.titleLabel.font.fontWithSize(20)  
} else if UIScreen.mainScreen().bounds.size.height == 568 { 
    // IPhone 5 
    mybutton.titleLabel.fontt = mybutton.titleLabel.font.fontWithSize(20) 
} else if UIScreen.mainScreen().bounds.size.width == 375 { 
    // iPhone 6 
    mybutton.titleLabel.font = mybutton.titleLabel.font.fontWithSize(20) 
} else if UIScreen.mainScreen().bounds.size.width == 414 { 
    // iPhone 6+ 
    mybutton.titleLabel.font = mybutton.titleLabel.font.fontWithSize(20) 
} else if UIScreen.mainScreen().bounds.size.width == 768 { 
    // iPad 
    mybutton.titleLabel.font = mybutton.titleLabel.font.fontWithSize(20) 
} 
相關問題