在以下代码中,我希望titleTextAttributesForState:
在创建UISegmentedControl
后返回默认文本属性,
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";}
我错过了什么吗?它也不会对属性进行编码。
我在- (void) encodeWithCoder:(NSCoder *)encoder
[encoder encodeObject:simpleButton forKey:@"simpleButton" ];
然后在我的-(id) initWithCoder:(NSCoder *)decoder
simpleButton = [decoder decodeObjectForKey:@"simpleButton"];
它不保存我设置的setTitleTextAttributes: forState:
。 (更改字体,大小和颜色)
我最终不得不添加:
[encoder encodeObject:[simpleButton titleTextAttributesForState:UIControlStateNormal] forKey:@"simpleButtonTitleTextAttributes" ];
和
[simpleButton setTitleTextAttributes:[decoder decodeObjectForKey:@"simpleButtonTitleTextAttributes"] forState:UIControlStateNormal];
表示要保存的文本属性。
谢谢,