difference between parseInt() and parseFloat() [duplicate]

JavaScript provides two methods for converting non-number primitives into numbers: parseInt() and parseFloat() . As you may have guessed, the former converts a value into an integer whereas the latter converts a value into a floating-point number. Any number literal contained in a string is also converted correctly, so the string “0xA” is properly converted … Read more

Fit text perfectly inside a div (height and width) without affecting the size of the div

Here’s the same answer, but in Javascript var autoSizeText; autoSizeText = function() { var el, elements, _i, _len, _results; elements = $(‘.resize’); console.log(elements); if (elements.length < 0) { return; } _results = []; for (_i = 0, _len = elements.length; _i < _len; _i++) { el = elements[_i]; _results.push((function(el) { var resizeText, _results1; resizeText = … Read more

Changing font size into an AlertDialog

You can actually get access to the message’s TextView pretty easily, and then change it’s size. I tested with a bigger size, but you could use whatever size you want. The text will scroll nicely as it already does. The view’s id is android.R.id.message AlertDialog dialog = new AlertDialog.Builder(this).setMessage(“Hello world”).show(); TextView textView = (TextView) dialog.findViewById(android.R.id.message); … Read more

How to change CollapsingToolbarLayout typeface and size?

Update Before we dive into the code let’s first decide the textSize for our CollapsingToolbarLayout. Google published a website called material.io, this website also explains the best way on how to deal with Typography. The article mentioned about “Heading” category which also explains the recommended font size to use in sp. Although the article never … Read more

Specify width in *characters*

ch unit The unit you’re looking for is ch. According to the MDN docs: ch: Represents the width, or more precisely the advance measure, of the glyph “0” (zero, the Unicode character U+0030) in the element’s font. It is supported in current versions of major browsers (caniuse). Example pre { width: 80ch; /* classic terminal … Read more

Resize font size to fill UITextView?

I have converted dementiazz’s answer to Swift: func updateTextFont() { if (textView.text.isEmpty || CGSizeEqualToSize(textView.bounds.size, CGSizeZero)) { return; } let textViewSize = textView.frame.size; let fixedWidth = textViewSize.width; let expectSize = textView.sizeThatFits(CGSizeMake(fixedWidth, CGFloat(MAXFLOAT))); var expectFont = textView.font; if (expectSize.height > textViewSize.height) { while (textView.sizeThatFits(CGSizeMake(fixedWidth, CGFloat(MAXFLOAT))).height > textViewSize.height) { expectFont = textView.font!.fontWithSize(textView.font!.pointSize – 1) textView.font = expectFont } … Read more