我使用下面的代碼來實現,並隨後改變每個段的字體大小在UISegmented控制如何改變分段控制的字體大小和防止它變回默認的大小變化的段
//Set up segment control
UISegmentedControl *tempSegmentControl = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:@"Friends",@"Popular", nil]];
tempSegmentControl.frame = CGRectMake(-8, -1, 336, 30);
self.segmentControl = tempSegmentControl;
[self.segmentControl setWidth:168 forSegmentAtIndex:0];
[self.segmentControl setWidth:168 forSegmentAtIndex:1];
self.segmentControl.selectedSegmentIndex = 0;
[self.segmentControl addTarget:self action:@selector(toggleControls:) forControlEvents:UIControlEventValueChanged];
[self.segmentControl setSegmentedControlStyle:UISegmentedControlStylePlain];
//TO CHANGE FONT SIZE OF EACH SEGMENT
for (id segment in [self.segmentControl subviews])
{
for (id label in [segment subviews])
{
if ([label isKindOfClass:[UILabel class]])
{
[label setTextAlignment:UITextAlignmentCenter];
[label setFont:[UIFont boldSystemFontOfSize:14]];
}
}
}
後
這個工程開始(見下圖)
然而,當我點擊「流行」選項卡(未激活選項卡)上,字體大小似乎回到原來的默認字體大小
我能做些什麼來防止字體大小更改回默認的大小?
你不能設置Interface Builder中的初始字體? – Besi 2012-03-13 02:31:16