这是针对工具栏项的。
以下代码可在iOS 6模拟器和iOS 6设备上正常运行。
在iOS 5模拟器和iOS 5设备中,阴影偏移量(UITextAttributeTextShadowOffset)被忽略。
[_doneButton setBackgroundImage:[UIImage imageNamed:@"standardButtonImage.png"]
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
NSDictionary *textDic = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Helvetica-Bold" size:15.0], UITextAttributeFont,
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor blackColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(1.0,1.0)], UITextAttributeTextShadowOffset, //won't honor the offset in ios5
// it's not the font, font size, text color, background image, or order in the dictionary. Must be an Apple bug.
// also doesn't work if you specify [UIBarButtonItem appearance]
nil];
[_doneButton setTitleTextAttributes:textDic forState:UIControlStateNormal];
有没有人有过同样的经历,或者有人可以看到这段代码有什么问题吗?
最佳答案
试试这个:UITextAttributeTextShadowOffset:[NSValue valueWithCGSize:CGSizeMake(1.0,1.0)];