If you want the ratio between the font size used by UILabel and the font size used by UIWebView (via CSS) from 1 to 1, you should use px instead of pt when determining the font size in your CSS.
Checkout this HTML / CSS example:
<html> <head> <style type='text/css'> body { font-family: 'SourceSansPro-Regular'; padding: 0 } .point { font-size: 17pt } .pixel { font-size: 17px } </style> </head> <body> <p class="point">About (17pt)<p> <p class="pixel">About (17px)</p> </body> </html>
When you add UIWebView and UILabel to your UIViewController and load the above HTML into a UIWebView and set the same font to UILabel :
override func viewDidLoad() { super.viewDidLoad() let webView = UIWebView(frame: CGRect(x: 25, y: 50, width:325 , height: 90)) view.addSubview(webView) let filePath = NSBundle.mainBundle().URLForResource("test", withExtension: "html") webView.loadRequest(NSURLRequest(URL: filePath!)) let label = UILabel(frame: CGRect(x: 25, y: 150, width: 325, height: 40)) label.font = UIFont(name: "SourceSansPro-Regular", size: 17) label.text = "About (UILabel set to 17)" view.addSubview(label) }
You get the following result:

joern Jul 11 '16 at 20:15 2016-07-11 20:15
source share