回答
由於UIButton的暴露了其titleLabel從iPhone開始OS 3.0,你必須直接設置字體給它:
[button.titleLabel setFont:[UIFont boldSystemFontOfSize:13]];
設置該按鈕的字體直接在SDK的3.x版本中進行了描述。相反,您需要設置按鈕的titleLabel屬性的屬性。
代碼:
(mybutton).titleLabel.font = [UIFont systemFontOfSize:13];
來源:http://www.iphonedevsdk.com/forum/iphone-sdk-development/26126-warning-setting-font-button.html
接受的答案的作品,並設置一個按鈕實例的字體。如果你想設置應用廣泛的字體爲所有UIButtons,你可以做這樣的:
// Set font to be used for labels inside UIButtons
[[UILabel appearanceWhenContainedIn:[UIButton class], nil] setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:15.0]];
這是不是在這個問題特別要求,但如果你需要設置字體爲所有標籤(未在UIButtons內),你可以這樣做:
// Set font for all UILabels
[[UILabel appearance] setFont:[UIFont fontWithName:@"HelveticaNeue" size:13.0]];
這是一個好主意。可悲的是,UILabel沒有UIAppearance代理中的字體屬性,這就是爲什麼字體不起作用。看到這個答案http://stackoverflow.com/questions/17127921/appearance-proxy-not-working-as-intended-for-uibutton-font – 2014-05-07 07:44:34
@EvaMadrazo你能詳細說明什麼是行不通的?我在我的項目中使用上面的代碼,它工作正常。爲了讓'appearanceWhenContainedIn'處理'UIButton',將按鈕類型設置爲'UIButtonTypeCustom'。 – lekksi 2014-05-07 11:44:25
@EvaMadrazo哦,你的意思是「爲所有標籤設置字體」不適用於'UIButton's?這是真的,我編輯答案更加清晰。 – lekksi 2014-05-07 11:50:53
- 1. [棄權] MultiJson.decode已棄用
- 2. 已棄用c#
- 3. 已棄用HttpClient?
- 4. Enum.ToString()已棄用?
- 5. 已棄用Httpclient
- 6. FAXCOMEXLIB已棄用?
- 7. stringWithContentsOfFile已棄用
- 8. DLR:IAttributesCollection已棄用?
- 9. UIPopoverController已棄用
- 10. 'itemFromNormalSprite:selectedSprite:target:selector:'已棄用
- 11. ISampleGrabber已棄用?
- 12. 已棄用notification.setLatestEventInfo
- 13. LSOpenApplication已棄用?
- 14. AndroidHttpClient已棄用
- 15. SetTimer已棄用?
- 16. glEnableClientState已棄用
- 17. CursorAdapter已棄用?
- 18. File.toURL()已棄用?
- 19. getch已棄用
- 20. Config.LOGD已棄用
- 21. AccountManager.removeAccount已棄用
- 22. OnCameraChangeListener()已棄用
- 23. setBackgroundColor已棄用
- 24. $ HADOOP_HOME已棄用
- 25. ProgressDialog已棄用
- 26. 棄用:函數eregi()已棄用
- 27. SoftLayer_User_Customer :: updatePassword已棄用
- 28. reversibleTransformerWithForwardBlock已被棄用
- 29. Blackberry MenuItem已棄用
- 30. setAllowsImageEditing已被棄用?
感謝您的信息! :) – 2013-04-03 13:21:38