Ios5 textTitleAttributesForState在设置之前为空,是否进行编码?
在下面的代码中,我希望在创建Ios5 textTitleAttributesForState在设置之前为空,是否进行编码?,ios5,uisegmentedcontrol,Ios5,Uisegmentedcontrol,在下面的代码中,我希望在创建UISegmentedControl后,titleTextAttributesForState:返回默认的文本属性 simpleButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"My Button"]]; simpleButton.segmentedControlStyle = UISegmentedControlStyleBar; sim
UISegmentedControl
后,titleTextAttributesForState:
返回默认的文本属性
simpleButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"My Button"]];
simpleButton.segmentedControlStyle = UISegmentedControlStyleBar;
simpleButton.momentary = YES;
simpleButton.tintColor = [UIColor blueColor];
NSLog(@"%@ - %@ - titleTextAttributesForState: %@", INTERFACENAME, NSStringFromSelector(_cmd) , [simpleButton titleTextAttributesForState:UIControlStateNormal]);
[simpleButton setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont boldSystemFontOfSize:12.0f], UITextAttributeFont,
nil]
forState:UIControlStateNormal];
NSLog(@"%@ - %@ - titleTextAttributesForState: %@", INTERFACENAME, NSStringFromSelector(_cmd) , [simpleButton titleTextAttributesForState:UIControlStateNormal]);
尽管从NSLog输出中可以看到,它不是
2011-11-03 17:28:45.492 io[80933:11903] IoUISESimpleButton - createElement - titleTextAttributesForState: (null)
2011-11-03 17:28:49.368 io[80933:11903] IoUISESimpleButton - createElement - titleTextAttributesForState: {
Font = "<UICFFont: 0x99c2040> font-family: \"Helvetica\"; font-weight: bold; font-style: normal; font-size: 12px";}
然后在我的-(id)initWithCoder:(NSCoder*)解码器中
[encoder encodeObject:simpleButton forKey:@"simpleButton" ];
simpleButton = [decoder decodeObjectForKey:@"simpleButton"];
它不会保存我设置的setTitleTextAttributes:forState:
。(更改字体、大小和颜色)
我最后不得不补充:
[encoder encodeObject:[simpleButton titleTextAttributesForState:UIControlStateNormal] forKey:@"simpleButtonTitleTextAttributes" ];
及
用于保存文本属性
谢谢
[simpleButton setTitleTextAttributes:[decoder decodeObjectForKey:@"simpleButtonTitleTextAttributes"] forState:UIControlStateNormal];