我不断遇到的每一个资源都是针对iOS的.我似乎无法让这个适用于Mac OSX.知道如何设置字体大小吗?它目前正确设置颜色和中心对齐.谢谢
NSMutableAttributedString *libTitle = [[NSMutableAttributedString alloc] initWithString:@"Library"]; [libTitle addAttribute:NSForegroundColorAttributeName value:[NSColor whiteColor] range:NSMakeRange(0,[@"Library" length] ) ]; [libTitle setAlignment:NSCenterTextAlignment range:NSMakeRange(0,[@"Library" length])]; [libTitle addAttribute:NSFontSizeAttribute value:[NSFont systemFontOfSize:18.0] range:NSMakeRange(0,[@"Library" length])]; [self.libbtn setAttributedTitle:libTitle];
解决方法
尝试在init方法中设置get go的字体属性:
NSFont *systemFont = [NSFont systemFontOfSize:18.0f]; NSDictionary * fontAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:systemFont,NSFontAttributeName,nil]; NSMutableAttributedString *libTitle = [[NSMutableAttributedString alloc] initWithString:@"Library" attributes:fontAttributes]; NSRange rangeOfTitle = NSMakeRange(0,[libTitle length]); [libTitle addAttribute:NSForegroundColorAttributeName value:[NSColor whiteColor] range:rangeOfTitle]; [libTitle setAlignment:NSCenterTextAlignment range:rangeOfTitle]; [self.libbtn setAttributedTitle:libTitle];