回答
由於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. Base64Encoding已棄用:iOS 7.0中已棄用
- 2. [棄權] MultiJson.decode已棄用
- 3. DLR:IAttributesCollection已棄用?
- 4. setCellValue已棄用
- 5. stringWithContentsOfFile已棄用
- 6. 'sharedDispatcher'已棄用
- 7. 'initWithFrame:reuseIdentifier'已棄用
- 8. UIPopoverController已棄用
- 9. CURLM_CALL_MULTI_PERFORM已棄用
- 10. 已棄用Httpclient
- 11. MKReverseGeocoder已棄用
- 12. AuthorizationExecuteWithPrivileges已棄用
- 13. SVNWCUtil.createDefaultAuthenticationManager已棄用
- 14. File.toURL()已棄用?
- 15. Android:getIntent()已棄用
- 16. 已棄用`route.transitionTo`?
- 17. OnCameraChangeListener()已棄用
- 18. FAXCOMEXLIB已棄用?
- 19. AndroidHttpClient已棄用
- 20. 'dismissModalViewControllerAnimated:'已棄用
- 21. 'gtk_widget_override_font'已棄用
- 22. GameObject.renderer已棄用
- 23. LSOpenApplication已棄用?
- 24. sharedScheduler已棄用?
- 25. 已棄用c#
- 26. ConstantScoreRangeQuery已棄用
- 27. dataTaskWithRequest:completionHandler:已棄用
- 28. cString已棄用?
- 29. SKPayment已棄用
- 30. Config.LOGD已棄用
感謝您的信息! :) – 2013-04-03 13:21:38