Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Increase font size of the UITextview,how?

I am trying to add two buttons to my app to set the font size of a UITextview,and i found this function

textview.font.increaseSize(...) //and decreaseSize(...) 

But i don't understand what I have to put inside the parentheses,i want to increase and decrease the font size by one point

Thanks for the answers

like image 521
GioB Avatar asked Feb 26 '15 12:02

GioB


People also ask

How do I increase text size in Swift?

To change the font or the size of a UILabel in a Storyboard or . XIB file, open it in the interface builder. Select the label and then open up the Attribute Inspector (CMD + Option + 5). Select the button on the font box and then you can change your text size or font.

How do I size a UITextView to its content?

It can be done using the UITextView contentSize . This will not work if auto layout is ON. With auto layout, the general approach is to use the sizeThatFits method and update the constant value on a height constraint. CGSize sizeThatShouldFitTheContent = [_textView sizeThatFits:_textView.

How do I change font size in Textview in Swift?

Swift 2 & 3:import UIKit extension UITextView { func increaseFontSize () { self. font = UIFont(name: (self. font?. fontName)!, size: (self.


1 Answers

I don't think there's a method named increaseSize(). May be you've find some UIFont or UITextView category.

The official UIFont class document doesn't reveal any such method.

Additionally you can increase the font like this:

textview.font = UIFont(name: textview.font.fontName, size: 18) 

The above statement will simply set the existing font size to 18, change it to whatever you want.

However if you want some method like you've posted, you can introduce your own category like this:

extension UITextView {     func increaseFontSize () {         self.font =  UIFont(name: self.font.fontName, size: self.font. pointSize+1)!     } } 

Swift 2 & 3:

import UIKit extension UITextView {     func increaseFontSize () {         self.font =  UIFont(name: (self.font?.fontName)!, size: (self.font?.pointSize)!+1)!     } } 

and simply import this to wherever you want to use like this:

textview.increaseFontSize() 

it'll increase the font by 1 every time you call it..

like image 136
Adil Soomro Avatar answered Sep 22 '22 04:09

Adil Soomro