What I want to achive is something like list view in Files App. Document will display a little thumbnail if has one. Otherwise a SF Symbol with textStyle .callout
will show up. All the rows’ labels should be left aligned. But currently the thumbnails are much bigger than the SF Symbols so that they push the labels away.
I emphasize textStyle because my app supports dynamic type, which means the imageView
's frame calculation should base on SF Symbol.
I try to override layoutSubviews
. But can't figure out how to do the calculation.
For maximum control of your cell appearance, you should create a custom cell. But, if you want use a standard
Subtitle
cell, you can resize your images when setting them.There are some excellent image scaling functions in this Stack Overflow answer: how to resize a bitmap on iOS
Add the extensions from that answer to your project. Specifically, for your needs, we'll use
scaledAspectFit()
.So, assuming you have a
Subtitle
cell prototype, with identifier of "cell", yourcellForRowAt
will look something like this:Edit
Takes only a little research to implement the use fo SF Symbols...
Add this func to your table view controller - it will return a
UIImage
of an SF Symbol at specified point size, centered in specified size:Then change your
cellForRowAt
func as needed:I'll leave it up to you to tweak the point size as desired (and configure any other properties of your SF Symbol image such as weight, scale, color, etc).