目前在我的每个视图中,我在viewDidLoad
事件中设置分段控件的高度,如下所示:
mySegmentedControl.frame = CGRect(
x: mySegmentedControl.frame.origin.x,
y: mySegmentedControl.frame.origin.y,
width: mySegmentedControl.frame.size.width,
height: 22)
它可以工作,但它很乏味,我希望我能在AppDelegate.didFinishLaunchingWithOptions
中做到这一点
var frame = UISegmentedControl.appearance().frame
UISegmentedControl.appearance().frame = CGRect(
x: frame.origin.x,
y: frame.origin.y,
width: frame.size.width,
height: 22)
但这没有任何影响,甚至是错误,它仍然是默认高度。我甚至尝试像这样对它进行子类化,但也没有效果或错误:
class SegmentedControl: UISegmentedControl {
override func sizeThatFits(size: CGSize) -> CGSize {
var sizeThatFits = super.sizeThatFits(size)
sizeThatFits.height = 22
return sizeThatFits
}
}
我是不是遗漏了什么,或者有一种全局设置高度的方法?
发布于 2015-08-05 16:20:33
也许是这样的:
UIFont *font = [UIFont boldSystemFontOfSize:14.0f];
NSDictionary *attributes = [NSDictionary dictionaryWithObject:font
forKey:NSFontAttributeName];
[segmentedControl setTitleTextAttributes:attributes
forState:UIControlStateNormal];
https://stackoverflow.com/questions/31789635
复制相似问题