以下哪项将设置 UISegmentedControl 的字体?
Which of the following will set the font of UISegmentedControl?
UIFont font = [UIFont boldSystemFontOfSize: 12.0f];
NSDictionary attributes = [NSDictionary dictionaryWithObject: font forKey: UITextAttributeFont];
[segmentedControl setTitleTextAttributes: attributes forState: UIControlStateNormal];
[[UISegmentedControl appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"STHeitiSC-Medium" size:13.0], UITextAttributeFont, nil] forState:UIControlStateNormal];
segmentedControl.transform = CGAffineTransformMakeScale(.6f, .6f);
None 其中
你可以这样做,
[segment setTitleTextAttributes:@{NSFontAttributeName :[UIFont fontWithName:@"HelveticaNeue" size:17.0], NSForegroundColorAttributeName : [UIColor darkGrayColor] } forState:UIControlStateNormal];
这里segment
是UISegmentedControl
对象。
UIFont font = [UIFont boldSystemFontOfSize: 12.0f];
NSDictionary attributes = [NSDictionary dictionaryWithObject: font forKey: UITextAttributeFont];
[segmentedControl setTitleTextAttributes: attributes forState: UIControlStateNormal];
上面的代码将更改一个特定段控件的字体,而下面的代码将更改您应用中所有段控件的字体。
[[UISegmentedControl appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"STHeitiSC-Medium" size:13.0], UITextAttributeFont, nil] forState:UIControlStateNormal];
并且此代码 segmentedControl.transform = CGAffineTransformMakeScale(.6f, .6f);
只会缩小您的段控制
注:
只需将已弃用的 UITextAttributeFont
替换为 NSFontAttributeName
即可在没有警告的情况下工作。
UIFont font = [UIFont boldSystemFontOfSize: 12.0f]; NSDictionary attributes = [NSDictionary dictionaryWithObject: font forKey: UITextAttributeFont]; [segmentedControl setTitleTextAttributes: attributes forState: UIControlStateNormal];
[[UISegmentedControl appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"STHeitiSC-Medium" size:13.0], UITextAttributeFont, nil] forState:UIControlStateNormal];
segmentedControl.transform = CGAffineTransformMakeScale(.6f, .6f);
None 其中
你可以这样做,
[segment setTitleTextAttributes:@{NSFontAttributeName :[UIFont fontWithName:@"HelveticaNeue" size:17.0], NSForegroundColorAttributeName : [UIColor darkGrayColor] } forState:UIControlStateNormal];
这里segment
是UISegmentedControl
对象。
UIFont font = [UIFont boldSystemFontOfSize: 12.0f];
NSDictionary attributes = [NSDictionary dictionaryWithObject: font forKey: UITextAttributeFont];
[segmentedControl setTitleTextAttributes: attributes forState: UIControlStateNormal];
上面的代码将更改一个特定段控件的字体,而下面的代码将更改您应用中所有段控件的字体。
[[UISegmentedControl appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"STHeitiSC-Medium" size:13.0], UITextAttributeFont, nil] forState:UIControlStateNormal];
并且此代码 segmentedControl.transform = CGAffineTransformMakeScale(.6f, .6f);
只会缩小您的段控制
注:
只需将已弃用的 UITextAttributeFont
替换为 NSFontAttributeName
即可在没有警告的情况下工作。