我正在尝试使用iOS FontAwesome在一个栏按钮上设置图标,如下所示:
[self.barButton setTitle:[NSString fontAwesomeIconStringForEnum:FACamera]];
以及这个:
[self.barButton setTitle:[NSString fontAwesomeIconStringForIconIdentifier:@"fa-camera"]];
无论我使用什么标识符,结果都是一样的:
![enter image description here](https://istack.dev59.com/hCjjM.webp)
我正在尝试使用iOS FontAwesome在一个栏按钮上设置图标,如下所示:
[self.barButton setTitle:[NSString fontAwesomeIconStringForEnum:FACamera]];
[self.barButton setTitle:[NSString fontAwesomeIconStringForIconIdentifier:@"fa-camera"]];
如果其他人也有这方面的疑问:
[self.barButton setTitleTextAttributes:@{
NSFontAttributeName: [UIFont fontWithName:@"FontAwesome" size:24.0],
NSForegroundColorAttributeName: self.view.tintColor
} forState:UIControlStateNormal];
[self.barButton setTitle:[NSString fontAwesomeIconStringForIconIdentifier:@"fa-camera"]];
在Swift中:
let filterButton = UIBarButtonItem(title: String.fontAwesomeIconWithName(FontAwesome.Filter), style: UIBarButtonItemStyle.Plain, target: self, action: Selector("filterClicked"))
filterButton.setTitleTextAttributes(NSDictionary(dictionary: [NSFontAttributeName:UIFont.fontAwesomeOfSize(25), NSForegroundColorAttributeName : UIColor.COLOR_BLUE_DARK]), forState: UIControlState.Normal)
self.navigationItem.rightBarButtonItem = filterButton
[self.barButton setTitleTextAttributes:@{
NSFontAttributeName: [FAKFontAwesome iconFontWithSize:20]
} forState:UIControlStateNormal];
[self.barButton setTitle:[FAKFontAwesome cameraIconWithSize:20].attributedString.string];
或者按照FontAwesomeKit文档中的建议将其转换为UIImage
:
FAKFontAwesome *cameraIcon = [FAKFontAwesome cameraIconWithSize:20];
UIImage *cameraImage = [cogIcon imageWithSize:CGSizeMake(20, 20)];
[self.barButton setImage:camera];
let button1 = UIBarButtonItem(title: "\u{f05a}", style: .plain, target: self, action: #selector(showCartInfoPopUp(_:)))
button1.setTitleTextAttributes([.font : UIFont(name: "Font Awesome 5 Pro", size: 24), .foregroundColor : UIColor.white], for: .normal)
self.navigationItem.rightBarButtonItem = button1
FontAwesome.ttf
作为按钮的必要要求? - holexUIButton
有一个font
属性 - 这可能是一个好的开始,但原作者有一个详细的描述来展示你如何做到这一点 - 如果你已经阅读了文档... - holexUIBarButtonItem
没有字体属性。(顺便说一句,不需要讽刺) - user623396