2016-07-28 11 views
1
  • UIFont font = [UIFont boldSystemFontOfSize: 12.0f]; NSDictionary attributes = [NSDictionary dictionaryWithObject: font forKey: UITextAttributeFont]; [segmentedControl setTitleTextAttributes: attributes forState: UIControlStateNormal];Welcher der folgenden Schritte wird die Schriftart von UISegmentedControl setzen?

  • [[UISegmentedControl appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"STHeitiSC-Medium" size:13.0], UITextAttributeFont, nil] forState:UIControlStateNormal];

  • segmentedControl.transform = CGAffineTransformMakeScale(.6f, .6f);

  • Nichts davon.

Antwort

2
UIFont font = [UIFont boldSystemFontOfSize: 12.0f]; 
NSDictionary attributes = [NSDictionary dictionaryWithObject: font forKey: UITextAttributeFont]; 
[segmentedControl setTitleTextAttributes: attributes forState: UIControlStateNormal]; 

Der obige Code wird Schriftart für eine bestimmte segmentcontrol ändern, während der folgende Code, um die Schriftart für alle segmentcontrol in Ihrer Anwendung ändern.

[[UISegmentedControl appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"STHeitiSC-Medium" size:13.0], UITextAttributeFont, nil] forState:UIControlStateNormal]; 

und dieser Code segmentedControl.transform = CGAffineTransformMakeScale(.6f, .6f); skaliert nur Sie Ihre segmentcontrol

Hinweis:

Ersetzen Sie einfach UITextAttributeFont mit NSFontAttributeName veraltet ohne Vorwarnung zu arbeiten.

+0

danke, große antwort – IvanovDeveloper

0

Sie können wie etwas tun,

[segment setTitleTextAttributes:@{NSFontAttributeName :[UIFont fontWithName:@"HelveticaNeue" size:17.0], NSForegroundColorAttributeName : [UIColor darkGrayColor] } forState:UIControlStateNormal]; 

hier segment ist UISegmentedControl Objekt.

0

In Odesk Test dieser beiden Varianten sind korrekt:

  • UIFont font = [UIFont boldSystemFontOfSize: 12.0f]; NSDictionary Attribute = [NSDictionary dictionaryWithObject: font forKey: UITextAttributeFont]; [segmentedControl setTitleTextAttributes: Attribute forState: UIControlStateNormal];
  • [[UISegmentedControl-Darstellung] setTitleTextAttributes: [NSDictionary-DictionaryWithObjectsAndKeys: [UIFont fontWithName: @ "STHeitiSC-Medium" Größe: 13.0], UITextAttributeFont, Null] forState: UIControlStateNormal];