系统需要,之前修改了一下分段控制器,今天由用到了,又细细的看了一遍分段控制器,是这样的:我之前是这样写的:
//修改系统的UISegmentControl
//修改字体大小
UIFont *font = PB_FONT_24;
NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
[_mSegmentControl setTitleTextAttributes:attributes forState:UIControlStateNormal];
//修改颜色
UIColor *textColor = PB_COLOR_17;
NSDictionary *textColorDic = [NSDictionary dictionaryWithObject:textColor forKey:NSForegroundColorAttributeName];
[_mSegmentControl setTitleTextAttributes:textColorDic forState:UIControlStateNormal];
UIColor *selectTextColor = PB_COLOR_1;
NSDictionary *selectTextColorDic = [NSDictionary dictionaryWithObject:selectTextColor forKey:NSForegroundColorAttributeName];
[_mSegmentControl setTitleTextAttributes:selectTextColorDic forState:UIControlStateSelected];
但是细细揣摩,这样写是不能完全修改它的字体和颜色一块修改的,为什么?因为我在设置字体的时候状态是normal,在修改颜色的时候还又用到了normal,会发生什么现象呢?在normal状态下,设置了两次属性,后边只能把前边的状态给冲掉,也就是说相当于是实际上只是设置了颜色,字体原来是多大还是多大,根本就没变化,有些同学该疑问了,怎么可能,字体和颜色又不相冲,字体设置字体,颜色设置颜色,说的是有一定道理的,但是再仔细想想又是没道理的,为什么这么说呢,你是字体设置字体,颜色设置颜色,可是你是在同一个状态下啊,所以说,这样是不行的,正确的应该是下边这样写,把一个状态下的所有药修改的属性都放在一块,完美解决,代码如下:
_mShowSegamentControl.tintColor = PB_COLOR_42;
[_mShowSegamentControl setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:PB_COLOR_17,NSForegroundColorAttributeName,PB_FONT_10,NSFontAttributeName, nil] forState:UIControlStateNormal];
[_mShowSegamentControl setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:PB_COLOR_1,NSForegroundColorAttributeName,PB_FONT_10,NSFontAttributeName, nil] forState:UIControlStateSelected];
Hope To Help You !
技术交流群:141624834 进群请说你看的那篇博客,我们一起探讨成长