更改segment的字体
还可以用ios5中的方法,可惜5.0之前的版本不能用
/*
* 更改UISegmentControl的字体
* 调用方法
* [CommonUtil ChangeSegmentFont:aSegmentControl fontSize:13];
*/
+ (void)ChangeSegmentFont:(UIView *)aView fontSize:(NSInteger)fontSize{
if ([aView isKindOfClass:[UILabel class]])
{
UILabel *lb = (UILabel *)aView;
[lb setTextAlignment:UITextAlignmentRight];
[lb setFont:[UIFont systemFontOfSize:fontSize]];
}
NSArray *na = [aView subviews];
NSEnumerator *ne = [na objectEnumerator];
UIView *subView;
while (subView = [ne nextObject])
{
[CommonUtil ChangeSegmentFont: subView fontSize:fontSize];
}
}
//假设是一个含有两个segment的UISegmentControl,将各个aView class打印的话
//依次是UISegmentControl UISegment、UILabel UISegment、UILabel
//如果想增加其他的subview 其实也挺简单 可以选择在UILabel上增加subview
还可以用ios5中的方法,可惜5.0之前的版本不能用
NSDictionary *textDic = [NSDictionary dictionaryWithObjectsAndKeys:
[[UIColor blackColor] colorWithAlphaComponent:0.6f],UITextAttributeTextColor,
[UIColor grayColor],UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(1, 0)],UITextAttributeTextShadowOffset,
[UIFont systemFontOfSize:13],UITextAttributeFont,nil];
[mySegment setTitleTextAttributes:textDic forState:UIControlStateNormal];