- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我想要在我的 NavigationBar 中有一个像这样的 UIBarButton Item
像这样的普通 UIButton
我已经尝试过使用这些链接 Question 1 Question 2 Question 3但没有得到输出。
我需要在 FontAwesome 图标上附加按钮标题文本。
有人可以帮忙吗?
我的代码是:
NSString *icon = [NSString fontAwesomeIconStringForIconIdentifier:@"fa-folder-open"];
NSString *locationString = [NSString stringWithFormat:@"%@ %@", icon, @"Change"];
NSMutableAttributedString *astring = [[NSMutableAttributedString alloc] initWithString:locationString];
[astring addAttribute:NSFontAttributeName
value:[UIFont iconicFontOfSize:20]
range:NSMakeRange(0,1)]; // The first character
changeFolderButton.titleLabel.attributedText = astring;
最佳答案
如果代码为FontAwesome
图标是""
, 然后将文本设置为 @"\U0000f007"
进入标题。
UIButton 使用以下代码:-
myBtn.titleLabel.font =[UIFont fontWithName:@"FontAwesome" size:20.0];
[myBtn setTitle:@"\U0000f007" forState:UIControlStateNormal]];
UIBarButton 使用以下代码:-
[self.barButton setTitleTextAttributes:@{
NSFontAttributeName: [UIFont fontWithName:@"FontAwesome" size:24.0],
NSForegroundColorAttributeName: self.view.tintColor
} forState:UIControlStateNormal];
[self.barButton setTitle:@"\U0000f007"]];
如果你想用图标附加你的字符串,那么使用下面的代码:-
NSString * myString = @"\U0000f007 Change";
NSMutableAttributedString *astring = [[NSMutableAttributedString alloc] initWithString:myString];
[astring addAttribute:NSFontAttributeName
value:[UIFont fontWithName:@"FontAwesome" size:22.0]
range:NSMakeRange(0,1)]; //If Icon is on starting position
[myBtn setAttributedTitle:astring forState:UIControlStateNormal];
希望,这就是您要找的。有任何疑虑,请回复我。 :)
关于iOS:在 UIBarButtonItem 和 Button 中附加带有标题的 FontAwesome 图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34468888/
我遇到过这个 html: 上面的html和这个有什么区别: 最佳答案 来自MDN page on the tag : 对于 type 的属性标签,可能的值是: 提交:按钮将表单数据提交给服务器
Button button= (Button) findViewbyID(R.id.button); 和 Button button = new Button(this); 有什么区别? 最佳答案 有
我是一名优秀的程序员,十分优秀!