Swift FontAwesome 5 Pro icons don't show programmatically - ios

In my swift app, I am using the pro version fontawesome. I got the name
Font Awesome 5 Pro
== FontAwesome5Pro-Light
and define it in a button as
var button = UIButton(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
button.titleLabel?.font = UIFont(name: "FontAwesome5Pro-Light", size: 20)
button.setAttributedTitle(NSMutableAttributedString(string: "\u{f13d}"), for: .normal)
button.setTitleColor(.systemBlue, for: .normal)
"\u{f13d}" is the unicode anchor icon Cheatsheet for FontAwesome
But the icon just comes out with the question mark in the square. If I create a button in the storyboard, set the font, create an outlet and then set the unicode from code behind it displays correctly.
I'm confused as to the cause. Any ideas?
Thanks ^.^

Setting the attributed title cancels the titleLabel?.font. Set the font of the attributed string.

Related

FontAwesome icon displayed as question mark

I am trying to set the button text for the following :
The first step I followed is to include the font file in the project. I then referred it in the Info.plist.
I copied the icon from the cheatsheet :
Then I set the font for the button in IB as follows :
As a result, I get a question mark on the button (both in IB and on running).
Just for cross checking, I set some other icon instead of this. It worked fine.
Where could the mistake be ?
You are using the wrong font. The one you want is FontAwesome5FreeSolid (fa-solid-900.ttf).
This works fine on my machine:
let s = "\u{f362} Convert"
let ss = NSAttributedString(string: s, attributes:
[.font : UIFont(name:"FontAwesome5FreeSolid", size:17)!])
let b = UIButton(type: .system)
b.frame = CGRect(x: 40, y: 40, width: 200, height: 200)
b.setAttributedTitle(ss, for: .normal)
self.view.addSubview(b)
Result:
In IB set only the font name and size , in code use something like this
self.backBu.setTitle(String(format:"%C",0xf053), for: .normal);
replace f053 with unicode that you want , also make sure that target memberShip is checked for the font resource and you add it to info.plist

UIButton titleLabel make as a circle

Hello I want to make UIButton title label as a circle. So I did in this way.
btnAttachments.setTitle(strcount, for: .normal)
btnAttachments.setTitleColor(UIColor.white, for: .normal)
btnAttachments.titleLabel?.backgroundColor=com.getRedcolor()
btnAttachments.titleLabel?.font=UIFont.init(name: "Bariol", size: 15)
btnAttachments.titleLabel?.layer.cornerRadius=(btnAttachments.titleLabel?.frame.width)!/2
But it doesn't make it as a circle. It looks like this code doen't affect on the titleLabel
UPDATE
This is what I want to make
Please help me
Thanks
well first you have to verify that the uibutton has its clipsToBounds true, but incase that s already set and the problem still there, then you probably trying to achieve this in the viewDidLoad which "should" work, but for some reason in some of the xcode 8 versions in the viewDidLoad the layout are still aint final (objects doesnt have their true dimensions set yet) you can verify this by logging the uibutton frame right before you assign the corner radius if you find some incoherent that this is probably the issue , incase this is the issue then you just need to move your code to viewWillAppear
You are missing to set MasToBounds
btnAttachments.titleLabel?.layer.masksToBounds = true;
add this you code will work fine ,
You should set corner redius in viewDidLayoutSubViews or drawRect(usually in UIView class)
i hope this will help u
Use the following code to get desired result:
let btnAttachments = UIButton(type: .custom)
btnAttachments.setTitle(strcount, for: .normal).setTitleColor(UIColor.white, for: .normal)
btnAttachments.frame = CGRect(x: 160, y: 100, width: 50, height: 50)
btnAttachments.titleLabel?.backgroundColor=com.getRedcolor()
btnAttachments.titleLabel?.font=UIFont.init(name: "Bariol", size: 15)
btnAttachments.layer.cornerRadius = 0.5 * button.bounds.size.width
btnAttachments.clipsToBounds = true

SVG UIBarbuttons are becoming big

Im using SVG images by converting them into PDF format. But sometimes, those barbutton items are becoming very big. Maximum of times am facing this issue is while using UIAlertController (Ex: Showing an alert, showing action sheet)
Here is the code i use to assign SVG as UIBarButtons
let search:UIButton = Utilities.getButton(forTitle: "", buttonType: .custom, image: IMAGE_SEARCH_SVG);
search.addTarget(self, action: #selector(handleSearchAction), for: .touchUpInside)
search.bounds = CGRect(x: 0, y: 0, width: H20, height: H20)
let searchBarBtnItem = UIBarButtonItem(customView: search)
self.navigationItem.rightBarButtonItem = searchBarBtnItem
u can see search icon on the top
on showing UIAlertAction,the search icon became big
Can someone help me in fixing this.

UIButton not highlighting the whole button when ImageEdgeInsets are set

I'm trying to have an UIButton with an image in the middle of it. I want this button to have edge insets of 10px. When I set these, I have the correct visual result but I can only click in a little area of this button.
How can I have the same visual but be able to click on the whole button ?
Here is my code :
self.descriptionViewMaleButton.setImage(UIImage(icon: "icon-male", backgroundColor: UIColor.whiteColor(), iconColor: UIColor.blackColor(), iconScale: 1.0, andSize: CGSize(width: 50, height: 50)), forState: UIControlState.Normal)
self.descriptionViewMaleButton.layer.borderColor = UIColor.grayColor().CGColor
self.descriptionViewMaleButton.layer.borderWidth = 1.0
self.descriptionViewMaleButton.imageEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10)
And the visual result :
EDIT : I am able to click on the whole button but it is highlighting only the image.
EDIT : I "fixed" that by implementing the highlighting myself. Anyway, if someones know more about this issue, I would be glad to know about it.

ios8/xcode6.1: custom font ignored at runtime when set in storyboard

I imported 2 *.ttf font files for a normal and bold font into xcode, set everything up in the .plist etc - and I can perfectly view the font in the storyboard now.
Unfortunately attributed textviews as well as labels or buttons will ignore my font when I set it in storyboard mode!
If I generate something programmatically it works fine, e.g. like this:
var testButton = UIButton()
testButton.setTitle("Abbrechen", forState: UIControlState.Normal)
testButton.backgroundColor = UIColor.blueColor()
testButton.titleLabel?.font = UIFont(name: "FaktConPro-Bold", size: 37)
testButton.tintColor = UIColor.redColor()
testButton.frame = CGRectMake(0 , 0, self.view.frame.width, 60)
view.addSubview(testButton)
any hints? does iOS prefer any format?
€dit:setting the labels and textfields to "plain" instead of "attributed" temporarily fixes the problem
This is a bug on Xcode. I already created a radar a couple of month ago. Here: http://openradar.appspot.com/radar?id=5117089870249984

Resources