I Have CollectionViewCell that has only UILabel(Same bounds as cell). I'm fetching array of fontNames as the CollectionView DataSource :
func printFonts() {
let fontFamilyNames = UIFont.familyNames()
for familyName in fontFamilyNames {
let names = UIFont.fontNamesForFamilyName(familyName as! String)
fontNames.append(familyName as! String)
}
}
I'm trying to display this font names in one line inside the UILabel , it works in some of the cases but in some not, and i have not idea why.
this is how i "adjust" the font inside cellForItemAtIndexPath
:
cell.lbl_font.adjustsFontSizeToFitWidth = true
cell.lbl_font.numberOfLines = 1
cell.lbl_font.minimumScaleFactor = 0.1
cell.lbl_font.baselineAdjustment = .AlignCenters
cell.lbl_font.textAlignment = NSTextAlignment.Center
as well i modified this properties via storyBoard :
Result :
UPDATE :
How do i apply text to the cell. where lbl_font
is the label inside the cell,
Inside cellForItemAtIndexPath
let cell : textCell = collectionView.dequeueReusableCellWithReuseIdentifier("text_cell", forIndexPath: indexPath) as! textCell
cell.lbl_font.text = fontNames[indexPath.row]
cell.lbl_font.font = UIFont(name:fontNames[indexPath.row], size: cell.lbl_font.font.pointSize)
cell.lbl_font.adjustsFontSizeToFitWidth = true
cell.lbl_font.numberOfLines = 1
cell.lbl_font.minimumScaleFactor = 0.1
cell.lbl_font.baselineAdjustment = .AlignCenters
cell.lbl_font.textAlignment = NSTextAlignment.Center
return cell
There is minimum font shrink property is available. it shrinks the font size as minimum ratio with the current point size. If the content become more then the ratio of fonts then it will defiantly shows the truncation dots(...) at the end.
For example :
Here I am setting up the property with minimum font scale is 0.4.
And here you can see different texts applied with the same property.
In first and second label will adjust the font size because content is less and it adjust as per minimum font scale ratio. but in 3rd the minimum font ratio and the content of the label is does not matched then it will show the dots(...) with truncation.
For this issue you should know that how mach content should be shown on that label or for batter use you can use multiline label.
Hope you will get help from the answer.