首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

改变segment式样,改变字体

2012-08-16 
改变segment样式,改变字体更改segment的字体/* * 更改UISegmentControl的字体 * 调用方法 * [CommonUtil C

改变segment样式,改变字体
更改segment的字体

/* * 更改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];

热点排行